Skip to content
Latchkey

What Is Docker Compose? Multi-Container Apps Explained

Docker Compose defines and runs multi-container applications from a single YAML file, so an app and its dependencies start together with one command.

Real applications need more than one container: a web service, a database, a cache. Docker Compose lets you declare all of them, their networks, and their configuration in one file, then bring the whole stack up or down with a single command, which is invaluable for local dev and CI.

What Docker Compose is

Docker Compose is a tool for defining and running multi-container Docker applications. A compose.yaml file lists services (containers), networks, and volumes with their configuration. The "docker compose" command reads it and manages the whole set as a unit.

How it works

Each service in the file maps to a container, built from a Dockerfile or pulled as an image, with ports, environment variables, and dependencies declared. Compose creates a shared network so services can reach each other by name. "docker compose up" starts everything; "down" tears it down cleanly.

A compose example

Two services wired together in one file.

A minimal compose.yaml
services:
  web:
    build: .
    ports: ["3000:3000"]
    depends_on: [db]
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: secret

Role in CI/CD

In CI, Compose is ideal for integration tests that need real dependencies: spin up the app plus a database and cache, run the tests against them, then tear it all down. "docker compose up -d" starts the stack in the background, tests run, and "down" cleans up. Starting full stacks is resource-heavy, so faster managed runners with warm image caches keep these jobs quick.

Alternatives

Testcontainers programmatically manages containers from within test code, which many teams prefer for integration tests. Kubernetes with kind or k3d runs a local cluster for more production-like setups. Compose remains the simplest way to declare and run a multi-container app for development and CI.

Key takeaways

  • Docker Compose runs multi-container apps from one YAML file.
  • It networks services together and manages them as a unit.
  • In CI it is ideal for spinning up real dependencies for integration tests.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →