Docker Compose for Laravel + MySQL
A PHP Laravel application with MySQL database. The most popular PHP web framework.
php laravel mysql fullstack
compose.yaml
services:
app:
build: .
ports:
- target: 8000
mode: ingress
environment:
- APP_ENV=production
- APP_KEY=${APP_KEY}
- DB_CONNECTION=mysql
- DB_HOST=db
- DB_PORT=3306
- DB_DATABASE=laravel
- DB_USERNAME=laravel
- DB_PASSWORD=${DB_PASSWORD}
healthcheck:
test:
- CMD
- curl
- -f
- http://localhost:8000/
interval: 30s
timeout: 5s
retries: 3
depends_on:
- db
deploy:
resources:
reservations:
cpus: "0.5"
memory: 256M
restart: unless-stopped
db:
image: mysql:8
ports:
- target: 3306
mode: host
environment:
- MYSQL_DATABASE=laravel
- MYSQL_USER=laravel
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
healthcheck:
test:
- CMD
- mysqladmin
- ping
- -h
- localhost
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
reservations:
cpus: "0.5"
memory: 256M
restart: unless-stopped
Services
- app .
- db mysql:8