Skip to content

Docker compose to setup nginx, php and mysql for laravel '7.16.1'.

Notifications You must be signed in to change notification settings

LERUfic/laravel-docker

Repository files navigation

Dockerize Laravel

Docker compose to setup nginx, php and mysql for laravel 7.16.1.

Directory Structure

laravel-docker
├── docker
│   ├── mysql
│   │   └── based.sql
│   ├── nginx
│   │   └── nginx.conf
│   └── php
│       └── Dockerfile
├── docker-compose.yml
├── init-storage
│   └── uploads
└── reset-db.sh

Images

  1. nginx → nginx:latest
  2. php → php:7.4-fpm
  3. mysql → mysql:5.7

Setup Initial DB

You can choose between using seeder or your own sql file for initial database.

Using Seeder

  1. 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
  2. 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

Using SQL File

  1. 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
  2. Make sure line 11 in file docker-compose.yml is uncommented
    11 - ./docker/mysql/based.sql:/docker-entrypoint-initdb.d/based.sql
  3. Copy your sql file to docker/mysql with based.sql as a file name.

Setup Initial storage

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.

Deployment using Docker

  1. Deploy nginx, php-fpm, and mysql using docker-compose
    docker-compose up -d
  2. Stop all container
    docker stop leru_nginx leru_mysql leru_php_fpm
  3. Remove all container
    docker rm leru_nginx leru_mysql leru_php_fpm
  4. Remove php-fpm image
    docker rmi laravel-docker_php_fpm
  5. Reset mysql data
    bash reset-db.sh

About

Docker compose to setup nginx, php and mysql for laravel '7.16.1'.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published