Containers & orchestrationIntermediate4h

Docker Compose.

Defining multi-container local environments in one file.

What is Docker Compose?

Compose describes a set of containers — your app, a database, a cache — and how they connect, in a single YAML file. One command brings the whole environment up or down. It is the standard way to run a multi-service stack on your laptop.

Why it matters

Real apps are rarely one container; they need a database, maybe Redis, maybe a queue. Compose makes spinning up that whole stack a one-liner, so every developer and CI run gets the same environment. It is the gentle on-ramp to orchestration before Kubernetes.

What to learn

  • The Compose file: services, networks, volumes
  • Service dependencies and startup order
  • Environment variables and .env files
  • Named volumes for persistent data
  • Exposing and mapping ports
  • depends_on versus real readiness
  • Compose for local dev versus production reality

Common pitfall

Relying on depends_on to mean "the database is ready." It only waits for the container to start, not for the service inside to accept connections, so your app races ahead and fails to connect. Add a real healthcheck or retry logic so the app waits for the dependency to actually be ready.

Resources

Primary (free):

Practice

Write a Compose file that runs your app alongside a Postgres container, with a named volume for the database and environment variables for credentials. Bring it up with one command and confirm the app connects. Add a healthcheck so the app waits for the database. Done when the whole stack starts from scratch cleanly.

Outcomes

  • Define a multi-service stack in a Compose file.
  • Connect services over a Compose network.
  • Persist data with named volumes.
  • Wait for real readiness instead of just container start.
Back to DevOps roadmap