Docker Compose is a tool for defining and running multi-container Docker applications using a single YAML configuration file. Originally written in Python (v1) and now rewritten in Go (v2), it simplifies orchestrating complex applications by managing service definitions, networking, volumes, and dependencies through declarative configuration rather than imperative commands. Docker Compose is essential for local development environments, integration testing, and single-host production deployments where full orchestration platforms like Kubernetes would be overkill. One critical insight: while Compose handles service startup order through depends_on, it does not wait for services to be ready—only for containers to start. This is why health checks and service_healthy conditions are crucial for reliable multi-container orchestration.
What This Cheat Sheet Covers
This topic spans 25 focused tables and 176 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Essential CLI Commands
| Command | Example | Description |
|---|---|---|
docker compose up -d | • Builds, (re)creates, starts, and attaches to containers • -d runs detached (background mode), aggregates logs by default when run in foreground | |
docker compose down -v | • Stops and removes containers, networks, and optionally volumes (-v) and images (--rmi)• cleans up the entire stack | |
docker compose ps --all | • Lists containers for services • --all includes stopped containers, shows status, ports, and health | |
docker compose logs -f web--tail=100 | • Views output from containers • -f follows log output in real-time, --tail limits lines, --timestamps adds timestamps | |
docker compose exec web sh | • Runs command in a running service container • -it for interactive shell, -u sets user, does not create new containers | |
docker compose run --rm test npm test | • Starts a new container for one-off commands or scripts • --rm removes container after run, does not start dependencies by default | |
docker compose build --no-cache | • Builds or rebuilds service images • --no-cache ignores build cache, --pull always attempts to pull newer base images | |
docker compose pull | • Pulls service images from registry • useful before up to ensure latest images, --ignore-pull-failures continues on error |