Docker Compose Patterns for Local Development
Stop fighting environment setup. Learn Docker Compose patterns that make local development reproducible and painless.
Docker Compose Patterns for Local Development
Every developer has experienced it: "works on my machine." Docker Compose solves this by making your development environment reproducible.
The Basic Pattern
version: "3.8"
services:
app:
build: .
ports:
- "3000:3000"
volumes:
- .:/app
- /app/node_modules
environment:
- DATABASE_URL=postgres://user:pass@db:5432/myapp
depends_on:
- db
db:
image: postgres:16-alpine
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: myapp
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
volumes:
pgdata:
Hot Reload with Volumes
The key to a good DX is the volume mount:
volumes:
- .:/app # Mount your code
- /app/node_modules # But keep node_modules in the container
This gives you hot reload while keeping platform-specific native modules correctly compiled for the container's OS.
Multi-Service Development
For microservice architectures, compose files become your orchestration layer:
services:
frontend:
build: ./frontend
ports: ["3000:3000"]
api:
build: ./api
ports: ["4000:4000"]
depends_on: [db, redis]
worker:
build: ./worker
depends_on: [db, redis]
db:
image: postgres:16-alpine
redis:
image: redis:7-alpine
Health Checks
Don't just use depends_on — add health checks:
db:
image: postgres:16-alpine
healthcheck:
test: ["CMD-SHELL", "pg_isready -U user"]
interval: 5s
timeout: 5s
retries: 5
app:
depends_on:
db:
condition: service_healthy
Conclusion
Docker Compose transforms local development from a setup nightmare into a single docker compose up command. Invest the time to get it right — your team will thank you.