Simple docker-compose environment for Laravel application with health check
Docker is used for containerisation, docker-compose is used for containers orchestration.
Basic docker configurations are provided in docker/ directory, separated by necessary services for the system running, aka:
- nginx
- php-fpm
- mysql
- redis
Each directory contains Dockerfile that allows to build specific docker image that then can be orchestrated via docker-compose.
Default project services orchestration settings are located at docker-compose.yml.
php-fpm + nginx setup has been chosen over artisan self-serving to provide more flexibilty for future extension, however it can be replaced in case if we need more simplicity for some specific project.
Environment variables via .env files are used to manage both docker and application environment settings.
Basic list of environment variables is provided in .env.example.
However, in order to run project locally, you need to have .env, which can be copied from .env.example and updated with necessary environment variables.
By default, .env.example should contain values to start project out of the box locally.
In order to build and run the project using docker-compose, you can use the next command:
docker-compose up -d --buildIf you'd like to run project without rebuild you can just run:
docker-compose up -dAll commands should be executed from php-fpm container, in order to do that you can use following command to login to php-fpm container shell:
docker exec -it php-fpm /bin/bashAlternatively, you can setup default php interpreter in your IDE to use docker php version, then you can just run commands directly from the IDE.
Please pay attention, that you need to set up app key on the first app setup. To do that please run:
php artisan key:generate
All commands listed in this section should be executed from php-fpm docker container shell.
In order to install packages execute command:
composer installIn order to run migrations execute command:
php artisan migrateIn order to clean cache execute command:
php artisan cache:clearThe code in this project is licensed under Apache License license.