Skip to content
StackDecode
IntermediateLesson 11 of 26

Compose in practice

Health-based startup, profiles, overrides and rebuilds.

depends_on only controls start order. To wait until a service is actually ready, combine it with a healthcheck.

yaml
services:
  db:
    image: postgres:16
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U postgres']
      interval: 5s
      retries: 10
  web:
    build: .
    depends_on:
      db:
        condition: service_healthy
    profiles: ['app'] # only starts with --profile app
  • compose.override.yaml is merged automatically: put dev-only settings there.
  • docker compose up --build rebuilds images; docker compose watch syncs code changes.