The idea of the project is to provide a pre-configured docker platform for Laravel and Lumen apps to get them up and running fast.
Credit: this is a kind of fork from maxpou/docker-symfony. Thanks to him :-)
I have made the number of changes to work with Laravel or Lumen apps and modified platform level commands (artisan
, composer
, mysql
) quite easy to access.
I assume you have docker-compose
installed and either docker-engine running locally (Linux) or have docker-machine (installed via docker-toolbox on OSX, Windows)
configured on the computer you use.
-
Retrieve git project
$ git clone git@github.com:purinda/docker-laravel.git
-
Change directory to the
docker-laravel
(cd docker-laravel
) -
Symlink your Laravel/Lumen project into app folder (
ln -s <absolute-path-of-laravel-project> app
) -
Build and start containers in detached mode.
$ docker-compose up -d
-
Update your host file (add
app.dev
)# get containers IP address and update host (replace IP according to your configuration ) $ docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -f name=nginx -q) $ sudo echo "10.211.55.7 app.dev" >> /etc/hosts
If you use
docker-machine
(mainly OSX or Windows) then run the following to get IP address of the vm.$ docker-machine ip <machine-name> $ echo "10.211.55.7 app.dev" | sudo tee -a /etc/hosts
-
Prepare Laravel/Lumen app
-
Update app/.env (adapt hosts according to previous results)
# Docker database configuration DB_CONNECTION=mysql DB_DATABASE=laravel DB_DATABASE_TEST=laravel_test DB_HOST=app.dev DB_PORT=3306 DB_USERNAME=laravel DB_PASSWORD=laravel # Docker SMTP MailCatcher configuration MAIL_DRIVER=smtp MAIL_HOST=app.dev MAIL_PORT=25 MAIL_FROM_ADDRESS=docker@local MAIL_FROM_NAME="Docker"
-
Composer install
$ docker-compose exec php composer install
-
-
Enjoy :-)
- Laravel app: visit app.dev
- Logs (Kibana): app.dev:81
- Logs (files location): logs/nginx and logs/laravel
- MailCatcher: app.dev:82
- For instructions please refer to https://mailcatcher.me/
Have a look at the docker-compose.yml
file, here are the docker-compose
built images:
application
: This is the Laravel or Lumen application code container,db
: This is the MySQL database container,php
: This is the PHP-FPM container in which the application volume is mounted,nginx
: This is the Nginx webserver container in which application volume is mounted too,elk
: This is a ELK stack container which uses Logstash to collect logs, send them into Elasticsearch and visualize them with Kibana,redis
: This is a redis database container.
This results in the following running containers:
$ docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------
dockerlaravel_application_1 /bin/bash Up
dockerlaravel_db_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp
dockerlaravel_elk_1 /usr/bin/supervisord -n -c ... Up 0.0.0.0:81->80/tcp
dockerlaravel_nginx_1 nginx Up 443/tcp, 0.0.0.0:80->80/tcp
dockerlaravel_php_1 php-fpm Up 9000/tcp
dockerlaravel_redis_1 docker-entrypoint.sh redis ... Up 0.0.0.0:6379->6379/tcp
# Composer (e.g. composer update)
$ docker-compose exec php composer update
# Laravel Artisan commands (make sure `artisan` script in the app has executable permissions bit set)
$ docker-compose exec php ./artisan
# bash commands
$ docker-compose exec php /bin/bash
# MySQL commands
$ docker-compose exec db mysql -uroot -p"toor" laravel
# Redis commands
$ docker-compose exec redis redis-cli
# Cache/logs folder permissions (use open permissions for development only)
$ chmod -R 777 app/storage/cache app/storage/logs
In order to run the application test suite, it is required to run phpunit
which runs against the test database of the
application layer.
The script setup-phpunit.sh
sets up the test database in the db
container and grants required permission for the application
test suite.
Script needs docker-machine environment variables (docker-machine env <machine-name>
) to be set if you are running
containers on docker-machine
. Run the script on docker-laravel
project directory as below. The script will copy itself into
the db container and set up the required configuration.
./setup-phpunit.sh
Lastly, run the unit test suite
docker-compose exec php php vendor/bin/phpunit