Docker compose to setup nginx, php and mysql for laravel 7.16.1.
laravel-docker
├── docker
│ ├── mysql
│ │ └── based.sql
│ ├── nginx
│ │ └── nginx.conf
│ └── php
│ └── Dockerfile
├── docker-compose.yml
├── init-storage
│ └── uploads
└── reset-db.sh
- nginx → nginx:latest
- php → php:7.4-fpm
- mysql → mysql:5.7
You can choose between using seeder or your own sql file for initial database.
- Open file docker/php/Dockerfile and uncomment lines 30-32
Before: 30 # RUN php artisan migrate:reset 31 # RUN php artisan migrate 32 # RUN php artisan db:seed After: 30 RUN php artisan migrate:reset 31 RUN php artisan migrate 32 RUN php artisan db:seed
- Open file docker-compose.yml and comment line 11
Before: 11 - ./docker/mysql/based.sql:/docker-entrypoint-initdb.d/based.sql After: 11 # - ./docker/mysql/based.sql:/docker-entrypoint-initdb.d/based.sql
- Make sure lines 30-32 in file docker/php/Dockerfile are commented
30 # RUN php artisan migrate:reset 31 # RUN php artisan migrate 32 # RUN php artisan db:seed
- Make sure line 11 in file docker-compose.yml is uncommented
11 - ./docker/mysql/based.sql:/docker-entrypoint-initdb.d/based.sql
- Copy your sql file to docker/mysql with based.sql as a file name.
In this deployment we use command php artisan storage:link to connect public directory with storage directory.
Since:
public/storage → storage/app/public
Therefore:
public/storage/uploads ≍ storage/app/public/uploads
To setup initial files for storage directory just paste your file into init-storage/uploads and Dockerfile will copy those file when creating php image.
- Deploy nginx, php-fpm, and mysql using docker-compose
docker-compose up -d
- Stop all container
docker stop leru_nginx leru_mysql leru_php_fpm
- Remove all container
docker rm leru_nginx leru_mysql leru_php_fpm
- Remove php-fpm image
docker rmi laravel-docker_php_fpm
- Reset mysql data
bash reset-db.sh