Docker Compose

Docker Compose is a tool for defining and running multi-container applications on a single host using a declarative YAML file. It is the standard way to spin up a local development environment with a database, a cache, the application server, and any other supporting services in one command.

How it works

A docker-compose.yml (or compose.yaml) file declares services, networks, volumes, and configuration. Each service describes one container (image, command, ports, environment, volumes, depends_on, healthcheck). Running docker compose up pulls images, creates the declared resources, starts containers in dependency order, and streams logs to the terminal.

Common features

  • Profiles. Mark services as belonging to optional profiles, started only when explicitly requested.
  • Environment files. .env files supply variables for substitution in compose.yaml.
  • Healthchecks and dependencies. Wait for one service to be healthy before starting another.
  • Override files. Compose merges compose.yaml with compose.override.yaml, useful for per-developer customisation.
  • Watch mode. Live-rebuild services on file changes during development.

Compose vs Kubernetes

Compose is for a single host and dev or simple staging environments. Kubernetes is for multi-host clusters in production. Compose specifications and Kubernetes manifests are not interchangeable but tools like Kompose can translate between them.

🔗
Related Terms
Docker, Kubernetes, containerd, OCI.

Subscribe to Sahil's Playbook

Clear thinking on product, engineering, and building at scale. No noise. One email when there's something worth sharing.
[email protected]
Subscribe
Mastodon