What is Docker Compose?

· Category: Docker

Short answer

Docker Compose is a tool for defining and running multi-container Docker applications. With a single docker-compose.yml file, you configure services, networks, and volumes, then start everything with docker compose up.

How it works

Compose reads the YAML file and creates the necessary networks, volumes, and containers. It manages dependencies between services, ensuring databases start before applications. Compose also rebuilds images when Dockerfiles change and handles service scaling.

Example

version: "3.9"
services:
  web:
    build: ./web
    ports:
      - "5000:5000"
  redis:
    image: redis:alpine

Start the stack:

docker compose up -d

Why it matters

Compose eliminates the need to run multiple docker run commands manually. It provides a reproducible development environment that can be version-controlled. This makes onboarding new developers faster and ensures everyone runs the same stack locally.

Common issues

  • Version mismatches between docker-compose (v1) and docker compose (v2) can cause subtle behavior differences.
  • Relative paths in volumes are resolved from the Compose file location.
  • Changes to docker-compose.yml require docker compose up -d to recreate affected containers.