Services

Resources

Company

Docker Compose

Docker Compose is a tool for defining and running an application made of several containers. You describe the services, networks and volumes in one YAML file, usually compose.yaml, and docker compose up creates and starts all of them together. It is the usual way to run an API with its database and other dependencies on a laptop or a single host.

How it works

Each entry under services names an image or a build context, plus ports, environment variables and volumes. Compose puts the services on a shared network where they reach each other by service name, so the API connects to db:5432 instead of an IP address. depends_on sets the start order, and with condition: service_healthy Compose waits for the dependency's healthcheck to pass, not just for its container to start.

For the SRE bootcamp's REST API, a compose.yaml can define two services: db from postgres:16 with a healthcheck of pg_isready -U app every 5 seconds and 5 retries, and api with depends_on: db: condition: service_healthy. docker compose up -d starts db, waits until it reports healthy, then starts api, which runs its migrations against db:5432. If db is still failing after 5 checks, about 25 seconds, api is never started and the command reports the unhealthy dependency.

Why it matters in production

Compose is built for one host. It can restart a crashed container, but it does not move containers to another machine, spread replicas across nodes or roll out updates gradually, which is why larger production fleets move to container orchestration such as Kubernetes. Its strength is a reproducible stack: the same file brings up the same services for every developer and in CI, and it is enough for small single-host deployments like the bootcamp's bare-metal exercise.

See also

On the One2N blog

References

  1. Docker Compose (Docker documentation)

  2. Control startup and shutdown order in Compose (Docker documentation)

Four-panel comic about Docker Compose: Asha starts an API and its Postgres database by hand and the migrations fail because the database is not ready; a compose.yaml lists both services on one network; db gets a pg_isready healthcheck every 5 seconds with 5 retries and api waits for service_healthy; docker compose up -d brings the whole stack up with one command.