DevOps & ContainersUpdated: 2026-11-07

The Production Docker Compose Cheat Sheet: Services, Volumes, Networks & Healthchecks

Quick reference for multi-container orchestration: restart policies, healthcheck probes, isolated bridge networks, and environment variables.

Docker Compose allows developers to define and run complex multi-container Docker applications using a single declarative YAML file. Keep this quick reference card handy for managing web services, database clusters, and persistent volumes in staging and production.

Essential Docker Compose CLI Commands

Daily management commands for starting, inspecting, and stopping stacks.

Command SyntaxActionDescription
`docker compose up -d`Detached StartupBuilds, creates, and launches containers in the background.
`docker compose down -v`Tear Down with VolumesStops containers, networks, and permanently purges named volumes.
`docker compose logs -f --tail=100 web`Stream LogsFollows real-time stdout/stderr log output for specific service.
`docker compose exec -it db psql -U user`Execute ShellRuns an interactive shell or database CLI inside running container.

Production Service Architecture Block

Standard multi-container configuration with database healthcheck and restart policies.

Full Stack docker-compose.ymlyaml
version: "3.8"

services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    restart: always
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=postgres://app:secret@db:5432/appdb
    depends_on:
      db:
        condition: service_healthy
    networks:
      - internal-net

  db:
    image: postgres:16-alpine
    restart: always
    volumes:
      - db_data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: secret
      POSTGRES_DB: appdb
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app -d appdb"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - internal-net

volumes:
  db_data:

networks:
  internal-net:
    driver: bridge

Frequently Asked Questions

What is the difference between docker-compose (v1) and docker compose (v2)?

Docker Compose v2 is integrated natively into the official Docker CLI written in Go, replacing the deprecated standalone Python script `docker-compose`.

How do you handle zero-downtime container deployments?

Combine `docker compose up -d --no-deps --build <service>` with a reverse proxy like Nginx or Traefik that performs healthcheck routing.