Docker Compose lets you define your entire application stack in a single YAML file and spin everything up with one command. It is the standard for local development environments.
A Complete Laravel Stack
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
volumes:
- .:/var/www/html
depends_on:
- mysql
- redis
environment:
DB_HOST: mysql
REDIS_HOST: redis
networks:
- app-network
mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: laravel
volumes:
- mysql_data:/var/lib/mysql
ports:
- "3306:3306"
networks:
- app-network
redis:
image: redis:7-alpine
ports:
- "6379:6379"
networks:
- app-network
queue:
build: .
command: php artisan queue:work --tries=3
depends_on:
- mysql
- redis
networks:
- app-network
volumes:
mysql_data:
networks:
app-network:
driver: bridgeKey Commands
# Start all services in background
docker compose up -d
# View logs from all services
docker compose logs -f
# Rebuild after Dockerfile changes
docker compose up -d --build
# Stop and remove everything
docker compose down
# Stop and remove including volumes
docker compose down -vHealth Checks
mysql:
image: mysql:8.0
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5Profiles for Optional Services
mailpit:
image: axllent/mailpit
profiles: ["debug"]
ports:
- "8025:8025"# Only starts debug-profile services
docker compose --profile debug up -dCompose keeps your entire development environment reproducible and shareable with your team.