A simplified Docker Compose workflow that sets up a Linux (Alpine Linux), Caddy, Redis, and MariaDB network of containers for local Laravel development.
- Docker >= 20.10.8
- Docker Compose >= 1.26.0
-
Make sure you have docker and docker-compose installed.
-
Clone your code into the src directory.
-
Create a .env in this directory.
- PHPGROUP: This can be the username/group of the current user on the host machine.
- PHPUSER: This can be the username of the current user on the host machine.
- DB_DATABASE: This is the database your application wants to use.
- DB_USERNAME: This is the username the application connects to.
- DB_PASSWORD: This is the password of the database the application connects to.
-
Navigate to this directory in your terminal, Run:
docker-compose up -d --build caddy
-
Bringing up the services exposes the following services on your machine:
- caddy -
:8200
- mysql -
:3306
- redis -
:6379
- app -
:9001
- mailhog -
:8025
- caddy -
-
Composer
docker-compose run --rm composer update
-
Artisan
docker-compose run --rm app php artisan migrate
-
Php
docker-compose run --rm app php
Persisting mysql to the host machine disk is pretty easy.
- Create a directory on your machine. Example create a directory in the path: /data/mysql
- Modify the mysql under the services in the docker-compose.yml
- Change the volume mapping to the path on your local machine
The /data/mysql must be a directory that exists on your local machine.
volumes: - '/data/mysql:/var/lib/mysql'
- Kill the container using
docker-compose down
, then restart.
Persisting redis to the host machine disk is pretty easy.
- Create a directory on your machine. Example create a directory in the path: /data/redis
- Modify the redis under the services in the docker-compose.yml
- Change the volume mapping to the path on your local machine
The /data/redis must be a directory that exists on your local machine.
volumes: - '/data/redis:/bitnami/redis/datum'
- Kill the container using
docker-compose down
, then restart.
The current version of Laravel (8 as of today) uses MailHog as the default application for testing email sending and
general SMTP work during local development. The mailhog service is included in the docker-compose.yml
file, and spins
up alongside the laravel application, redis and mysql services.
To see the dashboard and view any emails coming through the system, visit localhost:8025 after
running docker-compose up -d caddy
.
If you want to enable the hot-reloading that comes with Laravel Mix's BrowserSync option, add the following to the end
of your Laravel project's webpack.mix.js
file:
.browserSync({
proxy: 'nginx',
open: false,
port: 4000,
});
From your terminal window at the project root, run the following command to start watching for changes with the npm container and its mapped ports:
docker-compose run --rm --service-ports npm run watch