Last time, I tried to build a Laravel environment with Docker Compose, but I had trouble handling Laravel. [Copy] Build Laravel development environment with Docker Compose
After all, I put it in a container and installed Laravel, but ... it's not good. As a result of thinking, I thought that Laravel should be managed in the repository together with docker-compose.yml and others. Yeah, maybe this is the best! I mean, there is only this! !!
Since it goes back and forth between each environment, it is described as follows.
[Mac]$Working in a Mac with a Mac terminal
[PHP]$Work by connecting to a PHP container from a Mac terminal
https://github.com/bobtabo/docker/blob/master/docker-compose.yml
services:
nginx:
・ ・ ・
volumes:
- ~/MountPoint/docker/home:/home/docker
・ ・ ・
php:
・ ・ ・
volumes:
- ~/Work/MountPoint/docker/home:/home/docker
・ ・ ・
db:
volumes:
- ~/Work/MountPoint/docker/db/data:/var/lib/mysql
・ ・ ・
The mount point was separated from the container files, but changed to the following to make it the same directory.
services:
nginx:
・ ・ ・
volumes:
- ./src:/home/docker
・ ・ ・
php:
・ ・ ・
volumes:
- ./src:/home/docker
・ ・ ・
db:
volumes:
- ./db:/var/lib/mysql
・ ・ ・
https://github.com/bobtabo/docker/blob/master/.gitignore
--No need to mount / var / lib / mysql. -No mount other than / home / docker / laravel is required.
/db
/src/*
!/src/laravel
The above is a template, but since it's a big deal, Laravel is also available. Since the PHP version of the Mac and the container are different, I work inside the container.
[Mac]$ docker-compose exec --user 1000 php bash
[PHP]$ composer create-project --prefer-dist laravel/laravel laravel "5.6.*"
[PHP]$ cd laravel
[PHP]$ composer require --dev barryvdh/laravel-ide-helper
[PHP]$ composer require --dev squizlabs/php_codesniffer
[PHP]$ mkdir bin
[PHP]$ vi bin/clear-laravel.sh
---
#!/bin/bash
php artisan view:clear
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan clear-compiled
php artisan config:cache
composer dump-autoload
php artisan ide-helper:generate
php artisan ide-helper:models -N
php artisan ide-helper:meta
find . -name '._.DS_Store' -type f -ls -delete
---
:wq
[PHP]$ vi .env.example
---
:%s/DB_HOST=127.0.0.1/DB_HOST=mysql/g
:%s/DB_DATABASE=homestead/DB_DATABASE=hoge/g
:%s/DB_USERNAME=homestead/DB_USERNAME=fuga/g
:%s/DB_PASSWORD=secret/DB_PASSWORD=docker#DOCKER1234/g
---
:wq
Complete! !! https://github.com/bobtabo/docker2
[Mac]$ cd <Arbitrary directory>
[Mac]$ git clone https://github.com/bobtabo/docker2.git docker
[Mac]$ cd docker
[Mac]$ docker-compose up -d
・ ・ ・
Creating mysql ... done
Creating php ... done
Creating nginx ... done
[Mac]$ docker-compose exec --user 1000 php bash
[PHP]$ pwd
/home/docker
[PHP]$ cd laravel
[PHP]$ composer install
[PHP]$ chmod -R 777 storage
[PHP]$ chmod -R 777 bootstrap/cache
[PHP]$ cp -p .env.example .env
[PHP]$ php artisan key:generate
[PHP]$ chmod 755 bin/clear-laravel.sh
[PHP]$ bin/clear-laravel.sh
[PHP]$ php artisan migrate:fresh --seed
Recommended Posts