Docker Compose
Docker Compose defines and runs multi-container apps with a docker-compose.yml file. One command starts all services: docker compose up.
Compose = a band conductor's sheet music. One YAML file says 'drums start, then bass, then guitar.' But depends_on is like saying 'guitar after drums' — it waits for the drummer to SIT DOWN, not to actually be PLAYING. Use healthchecks to wait for the beat.
Key fields: services, networks, volumes. depends_on controls startup order (but not readiness — the dependent service may start before the dependency is ready). Environment variables via env_file or environment. Health checks via healthcheck. Compose creates a default network where services are accessible by service name. Profiles group services for conditional startup. docker compose up -d (detached), down (stop + remove), logs, exec.
depends_on with condition: service_healthy waits for the healthcheck to pass — the right way to wait for a database to be ready. Compose V2 (docker compose vs docker-compose) is now the default and ships with Docker. Compose files support extension fields (x-) and anchors/aliases (YAML anchors) for DRY configs across environments. override files: docker-compose.override.yml is auto-merged — useful for local dev vs CI variations. In production, Compose is often replaced by Kubernetes, but it's still widely used for local dev and simple single-host deployments.
Docker Compose is the standard tool for local multi-service development. One YAML file defines all services, their images, env vars, ports, volumes, and network relationships. Services discover each other by service name on the default Compose network. The critical depends_on gotcha: it controls startup order but not readiness. Use depends_on with condition: service_healthy and a healthcheck to properly wait for databases and message queues to be ready before starting dependent services.
depends_on alone does NOT wait for a service to be ready — only for the container to start. A web service starting before its database is healthy will crash. Use condition: service_healthy with a proper healthcheck, or implement retry logic in your application startup.