Docker Compose for Local Stacks
Run PHP, a database and cache together locally.
Local Stacks with Compose
Real PHP apps are never just PHP — they need a database, a cache, sometimes a queue and a mail catcher. Docker Compose declares all of these as services in one file and wires them onto a shared network so they reach each other by name.
This lesson builds a full local stack: PHP-FPM + nginx + MySQL + Redis, with volumes, healthchecks, and dependency ordering.
Service Skeleton
A Compose file lists services under services:. Each can build from a Dockerfile or pull an image. Compose creates a default network where every service is reachable by its key — your PHP app connects to MySQL at host db, not localhost.
services:
app:
build:
context: .
target: dev # multi-stage dev target
volumes:
- ./:/app # live code mount
depends_on:
db:
condition: service_healthy
db:
image: mysql:8.4
redis:
image: redis:7-alpineAll lessons in this course
- Containerizing a PHP Application
- Multi-Stage Builds and Optimization
- Docker Compose for Local Stacks
- CI/CD with GitHub Actions