One Compose File, Multiple Environments
Docker Compose profiles let you define which services run in which environment. No more commenting out services.
docker-compose.yml
services:
app:
build: .
ports: ["3000:3000"]
depends_on: [db]
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: secret
redis:
image: redis:7
profiles: [prod]
mailhog:
image: mailhog/mailhog
ports: ["8025:8025"]
profiles: [dev]
pgadmin:
image: dpage/pgadmin4
ports: ["5050:80"]
profiles: [dev]
prometheus:
image: prom/prometheus
profiles: [monitoring]
Usage
# Dev (app + db + mailhog + pgadmin)
docker compose --profile dev up
# Prod (app + db + redis)
docker compose --profile prod up
# With monitoring
docker compose --profile prod --profile monitoring up
Why Profiles
- One file instead of docker-compose.dev.yml + docker-compose.prod.yml
- No service commenting/uncommenting
- Clear intent (which services belong where)
- Combinable (add monitoring to any environment)
More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs
Top comments (0)