Docker compose generator for a full Laravel setup
First, install Yeoman and generator-docker-laravel using npm (we assume you have pre-installed node.js).
npm install -g yo
npm install -g generator-docker-laravel
Then generate your new project:
yo docker-laravel
This generator creates a docker-compose file (docker-compose.yml
) and scripts (dc-aliases
/dc-aliases.bat
and update-notifications-service.sh
/update-notifications-service.bat
) that helps you build and run a full Laravel project inside a set of docker containers. You choose which containers are created. At the moment the following containers are available:
- NGINX container with FPM PHP 7.1 (mandatory)
- Database container (for the moment only MySQL is supported) (mandatory)
- Queue daemon used to run artisan queue command (includes a Redis container)
- Notifications daemon used to broadcast events using Socket.io (includes a Redis container)
- Adminer
Once generator-docker-laravel is installed go to your Laravel project folder, open a bash or command prompt window
yo docker-laravel
- Answer the generator prompts, and select which containers you want to setup
- Based on your options, the following files will be created:
docker-compose.yml
: the docker compose file where all services are defineddc-aliases
: a set of aliases to help manage the docker containers from bashdc-aliases.bat
: a set of aliases to help manage the docker containers from a Windows command promptupdate-notifications-service.sh
: bash script to recreate the NodeJS notifications daemon (when the code is changed the daemon should be updated)update-notifications-service.bat
: windows 10 command prompt script to recreate the NodeJS notifications daemon (when the code is changed the daemon should be updated)nodejs-apps
folder where the NodeJS notifications daemon sample app is stored- Enter:
source dc-aliases
to import the docker-compose alias into your terminal's session. Optionally you can copy them permanently to your shell's configuration file. On Windows, from the command prompt, just type:dc-aliases.bat
To launch the service containers just type:
dc-up
To stop and remove all containers type:
dc-down
To run common tasks use the following aliases:
dc-art
ordc-artisan
- to run artisan (e.g.dc-art migrate
)dc-phpunit
- to run phpunit (e.g.dc-phpunit tests
)dc-phpspec
- to run phpspec
The following aliases are provided for additional maintenance:
dc-adminer
- to launch the adminer containerdc-clear-generated
- to remove all generated images (all service containers must be stopped before running this command)
Important notes:
- Version 1.7 or greater of
docker-compose
is required because docker-compose configuration file reads environment variables from the Laravel .env file - Composer CLI must be installed to manage Laravel's package dependencies (the generator does not create a composer container)
- This generator is an improvement of my first approach to dockerize a Laravel project
Apache-2.0 © Vitor Carreira