C.W.K.
Stream
Lesson 04 of 04 · published

Profiles & Override Files — Dev vs Prod from One Repo

~14 min · compose, operations

Level 0Container Curious
0 XP0/36 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Profiles: optional services

Some services should only start when needed: a DB GUI, a mail catcher, a debug dashboard. Tag them with a profile and Compose ignores them by default.

Override files: dev vs prod without two compose files

Compose auto-merges compose.yaml with compose.override.yaml if the override exists. Convention: base file is prod-shaped, override file is dev-tweaks (bind mounts, --reload, debug ports). Production uses -f compose.yaml -f compose.prod.yaml instead.

Code

Profile for optional debug services·yaml
services:
  api:
    build: ./api
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: secret

  # Optional services
  adminer:
    image: adminer
    profiles: [debug]
    ports: ["8080:8080"]
  mailhog:
    image: mailhog/mailhog
    profiles: [debug]
    ports: ["1025:1025", "8025:8025"]
Override for dev hot-reload·yaml
# compose.override.yaml — auto-loaded in dev
services:
  api:
    volumes:
      - ./api:/app
    environment:
      APP_ENV: development
    command: uvicorn main:app --reload --host 0.0.0.0

# Use:
#   docker compose up -d            ← merges base + override (dev)
#   docker compose --profile debug up -d   ← also starts debug services
#   docker compose -f compose.yaml -f compose.prod.yaml up -d  ← prod

External links

Exercise

Add a debug profile to one of your compose stacks with adminer (or pgadmin) and mailhog. Verify they only start with --profile debug. Then add a compose.override.yaml that bind-mounts your source for hot-reload. Switch between dev and prod with -f and verify the difference.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.