Docker Compose
Tool for defining and running multi-container applications with a YAML file, simplifying local development of systems with multiple services.
seed#docker-compose#docker#local-development#yaml#multi-container#devops
What it is
Docker Compose is a tool for defining and running applications consisting of multiple Docker containers. A compose.yaml file describes all services, networks, and volumes, and a single command brings them all up.
Basic compose.yaml
services:
web:
build: .
ports:
- "3000:3000"
depends_on:
- db
environment:
DATABASE_URL: postgres://db:5432/app
db:
image: postgres:16
volumes:
- pgdata:/var/lib/postgresql/data
environment:
POSTGRES_DB: app
volumes:
pgdata:Essential commands
docker compose up: bring up all servicesdocker compose up -d: bring up in backgrounddocker compose down: stop and remove containersdocker compose logs -f: follow logs from all servicesdocker compose exec web sh: shell into a service
Use cases
- Local microservices development
- Testing environments with real dependencies
- Quick demos and prototypes
- CI/CD for integration tests
Compose vs Kubernetes
| Aspect | Docker Compose | Kubernetes |
|---|---|---|
| Purpose | Local development, CI | Production, orchestration at scale |
| Complexity | Low — one YAML file | High — multiple resources (Deployments, Services, Ingress) |
| Scaling | Manual (scale: 3) | Automatic (HPA, VPA) |
| Networking | Default bridge network | CNI plugins, service discovery |
| State | Stateful with local volumes | StatefulSets, PersistentVolumes |
| Migration | — | Kompose converts compose files to K8s manifests |
Why it matters
Docker Compose allows defining multi-container applications as code. For local development, it replaces complex setup scripts with a single command that starts databases, caches, and auxiliary services in the correct order.
References
- Docker Compose Documentation — Official documentation.
- Compose File Reference — Docker, 2024. Complete file format reference.
- Docker Overview — Docker, 2024. General Docker and Compose context.