/generator-docker-laravel

Yeoman generator to dockerize a full stack Laravel application

Primary LanguageJavaScriptOtherNOASSERTION

generator-docker-laravel NPM version Build Status Dependency Status Coverage Status

Docker compose generator for a full Laravel setup

Installation

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

Quick demo

generator-demo

Longer walkthrough videos

01. Basic walkthrough

02. Using adminer

03. The queue daemon

04. The notifications daemon

05. Managing containers

06. Windows 10 with Command Prompt only

Getting Started

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 defined
  • dc-aliases: a set of aliases to help manage the docker containers from bash
  • dc-aliases.bat: a set of aliases to help manage the docker containers from a Windows command prompt
  • update-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

Launching the containers

To launch the service containers just type:

dc-up

To stop and remove all containers type:

dc-down

Daily usage

To run common tasks use the following aliases:

  • dc-art or dc-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 container
  • dc-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

License

Apache-2.0 © Vitor Carreira