Simple setup Docker, for Laravel applications.
- Laravel APP -
php artisan serve
- Laravel Queue -
php artisan queue:work
- Laravel Schedule -
php artisan schedule:work
- MySQL
- Redis
- PHP
8.1-cli-alpine
- MySQL
8.0
- Redis
7.0-alpine
Minimum Laravel version for this project is: V8
$ git clone https://github.com/allysonsilva/simple-docker-laravel docker
docker
must be inside Laravel application_- The folder name is configurable via the
LOCAL_DOCKER_FOLDER
variable of the.env
environment file
- The folder name is configurable via the
The organization of the folders should serve as a reference for organizing this repository Docker + Laravel Application:
.
βββ /var/www/app
βββ app
βββ bootstrap
βββ config
βββ database
βββ docker <-------
βββ lang
βββ ...
- Execute command
make -f docker/Makefile docker/config-env
- Edit the variable
COMPOSE_PROJECT_NAME
, to a value that matches the application- Open the
.envrc
file and change the value of the prefixed variables fromapp_
to the value of theCOMPOSE_PROJECT_NAME
variable, so, for example:- If you set the value of the
COMPOSE_PROJECT_NAME
variable tomyapp
, change the value of thedatabase_container
variable in the.envrc
file tomyapp_database
and the value of theredis_container
variable tomyapp_redis
.
- If you set the value of the
- Open the
It is necessary to build the image that will be used by the application, queue and scheduling containers.
- Copy the
.dockerignore
file to a higher folder level with the commandcp docker/.dockerignore .
- Open the
.env
indocker/.env
file and edit the variables if necessaryAPP_IMAGE
,APP_LOCAL_FOLDER
APP_IMAGE
: Docker image tag that will be used in its creation through thedocker/build/app
command and also used in the execution of PHP/Laravel containersAPP_LOCAL_FOLDER
: Name of the folder where the Laravel application is located. Can be relative path (default) or absolute path to application folder
Use the command to build the image: make -f docker/Makefile docker/build/app
Use the command below to up the application containers, MySQL and Redis:
make -f docker/Makefile docker/up
If you want to recreate or create containers individually, use the commands:
- MySQL:
make -f docker/Makefile docker/database/up
- Redis:
make -f docker/Makefile docker/redis/up
- APP:
make -f docker/Makefile docker/app/up
- Queue:
make -f docker/Makefile docker/queue/up
- Scheduler:
make -f docker/Makefile docker/scheduler/up
Use the up_options
argument in the above commands to customize the arguments that will be passed in the up
command of docker-compose
. As follows: make -f docker/Makefile docker/app/up up_options="--force-recreate --no-deps"
- To see the list of options use the command: docker-compose up --help
Please see CHANGELOG for more information about the changes on this package.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.