Docker environment configuration for Laravel development. Contains settings for local development for new project or already existing.
Repository provides:
- Laravel 6
- PHP 7.4
- Nginx: 1.14
- MySql 8.0
- Redis
- Node latest
- LetsEncrypt for production
Note: Local environment tested only on Ubuntu. Feel free to create an Issue for other OS.
-
Clone repository
mkdir {YOUR_NEW_FOLDER} cd {YOUR_NEW_FOLDER} git clone git@github.com:dmsemenov/laravel-docker-environment.git . -
Configure main
.envfilecp .env.example .envSet
PROJECT_NAMEvariable.
SetPROJECT_FOLDERvariable for example 'backend' or whatever you want. By default it ismain. -
Install Application
Install or copy your existing application toPROJECT_FOLDER.# Install new composer create-project --prefer-dist laravel/laravel `PROJECT_FOLDER` -
Configure main
docker-compose.ymlfile# Local development cp docker-compose.yml.local docker-compose.ymlSet variables for mysql container. Docker will create database and user at first UP.
MYSQL_ROOT_PASSWORD: MYSQL_DATABASE: ${PROJECT_NAME} MYSQL_USER: ${PROJECT_NAME} MYSQL_PASSWORD: -
Configure Application
.env# By default ${PROJECT_FOLDER}=main cp ${PROJECT_FOLDER}/.env.example cp ${PROJECT_FOLDER}/.envSet variables from step 3
DB_HOST=mysql DB_DATABASE= DB_USERNAME= DB_PASSWORD= -
Run Application
# Run containers docker-compose up -d --build docker-compose exec php-fpm php artisan key:generate # Base UI docker-compose exec -uwww-data php-fpm composer require laravel/ui --dev docker-compose exec -uwww-data php-fpm php artisan ui bootstrap --auth # Build frontend docker-compose run --rm --no-deps -unode node bash -ci 'npm i&&npm run dev' # Migrate docker-compose exec -uwww-data php-fpm php artisan migrate docker-compose exec -uwww-data php-fpm composer install
Repository do not show full flow how to deploy docker application with build and docker registry, it can be used with simple git pull from your repository.
For production without https you can use develop branch and production files.
# Production cp docker-compose.yml.prod docker-compose.yml #this compose file use nginx production config If you are going to use LetsEncrypt at production look at branch 'letsencrypt' this repository. Branch contains ready to use configuration for letsEncrypt in production based on great article Nginx and Let’s Encrypt with Docker in Less Than 5 Minutes.
To use letsEncrypt at production just follow steps below:
- Initial settings
Open./init-letsencrypt.shadd your domains instead{YOUR_DOMAIN}www.`{YOUR_DOMAIN}` and set{YOUR_EMAIL}.
Run./init-letsencrypt.sh. It will create initial settings.
Note: don't forget to add A DNS record for domain with www. - Nginx settings
At.provision/nginx/conf.d/vhost.prod.confset{YOUR_DOMAIN}variable. Certificates stored at .provision folder and will be renew as described in article.