Concepts

Docker Compose

Tool for defining and running multi-container applications with a YAML file, simplifying local development of systems with multiple services.

seed#docker-compose#docker#local-development#yaml#multi-container#devops

What it is

Docker Compose is a tool for defining and running applications consisting of multiple Docker containers. A compose.yaml file describes all services, networks, and volumes, and a single command brings them all up.

Basic compose.yaml

services:
  web:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - db
    environment:
      DATABASE_URL: postgres://db:5432/app
  
  db:
    image: postgres:16
    volumes:
      - pgdata:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: app
 
volumes:
  pgdata:

Essential commands

  • docker compose up: bring up all services
  • docker compose up -d: bring up in background
  • docker compose down: stop and remove containers
  • docker compose logs -f: follow logs from all services
  • docker compose exec web sh: shell into a service

Use cases

  • Local microservices development
  • Testing environments with real dependencies
  • Quick demos and prototypes
  • CI/CD for integration tests

Compose vs Kubernetes

AspectDocker ComposeKubernetes
PurposeLocal development, CIProduction, orchestration at scale
ComplexityLow — one YAML fileHigh — multiple resources (Deployments, Services, Ingress)
ScalingManual (scale: 3)Automatic (HPA, VPA)
NetworkingDefault bridge networkCNI plugins, service discovery
StateStateful with local volumesStatefulSets, PersistentVolumes
MigrationKompose converts compose files to K8s manifests

Why it matters

Docker Compose allows defining multi-container applications as code. For local development, it replaces complex setup scripts with a single command that starts databases, caches, and auxiliary services in the correct order.

References

Concepts