Compose Configuration in Docker

From the Docker cheat sheet ยท Docker Compose ยท verified Jul 2026

Compose Configuration

Full compose.yml reference with depends_on, healthcheck, profiles, watch, and more

yaml
services:
  app:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      db:
        condition: service_healthy
    environment:
      DATABASE_URL: postgres://user:pass@db:5432/mydb

  db:
    image: postgres:17-alpine
    volumes:
      - db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  db-data:
๐Ÿ’ก depends_on with condition: service_healthy waits until the dependency passes its healthcheck
โšก Compose Watch syncs files without rebuilding โ€” use action: sync for source, action: rebuild for deps
๐Ÿ“Œ Profiles let you define optional services (debug tools, admin panels) that only start when requested
๐ŸŸข Use env_file to load .env files โ€” keeps secrets out of compose.yml and version control

Continue with Docker

Save the full cheat sheet or work through every related task.

More Docker tasks

Back to the full Docker cheat sheet