Docker Compose Profiles — Optional Services
Use Docker Compose profiles to selectively start optional services like monitoring, debugging tools.
version: '3.9'
services:
app:
build: .
ports:
- '3000:3000'
depends_on:
- postgres
postgres:
image: postgres:16-alpine
environment:
POSTGRES_PASSWORD: dev
ports:
- '5432:5432'
# Only started with: docker compose --profile monitoring up
prometheus:
image: prom/prometheus:latest
profiles: [monitoring]
ports:
- '9090:9090'
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana:latest
profiles: [monitoring]
ports:
- '3001:3000'
depends_on:
- prometheus
# Debug tools
pgadmin:
image: dpage/pgadmin4
profiles: [debug]
ports:
- '5050:80'
environment:
PGADMIN_DEFAULT_EMAIL: admin@local.dev
PGADMIN_DEFAULT_PASSWORD: admin
redis-commander:
image: rediscommander/redis-commander
profiles: [debug]
ports:
- '8081:8081'
# Usage:
# docker compose up → app + postgres only
# docker compose --profile monitoring up → + prometheus + grafana
# docker compose --profile debug up → + pgadmin + redis-commander
# docker compose --profile monitoring --profile debug up → everythingSponsored
DigitalOcean
Use Cases
- Optional monitoring stack for local development
- Debug tools available on demand without clutter
- Layered service composition for different workflows
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Docker Compose — PostgreSQL Dev Environment
Full Docker Compose setup for PostgreSQL with pgAdmin, init scripts, volumes, and health checks.
Best for: Local database development environment
Docker Compose — Multi-Environment Override
Use Docker Compose override files for dev, staging, and production with shared base configuration.
Best for: Shared base config with environment-specific overrides
SSH Config for Server Management
Organized SSH config file with host aliases, jump hosts, and connection multiplexing for DevOps.
Best for: Managing connections to multiple servers
Makefile for DevOps Automation
Makefile with common DevOps targets for building, testing, deploying, and managing Docker containers.
Best for: Standardizing developer commands across teams