Docker
Beginner
1 min read
Compose Profiles and Scaling Services
Example
# compose.yaml with profiles and scaling
services:
db:
image: postgres:16-alpine
environment:
POSTGRES_PASSWORD: secret
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD","pg_isready"]
interval: 5s
retries: 10
api:
build: .
expose:
- "3000"
environment:
DATABASE_URL: postgres://postgres:secret@db:5432/postgres
depends_on:
db:
condition: service_healthy
nginx:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- api
pgadmin:
image: dpage/pgadmin4
profiles: [debug]
ports:
- "5050:80"
environment:
PGADMIN_DEFAULT_EMAIL: admin@local.dev
PGADMIN_DEFAULT_PASSWORD: admin
volumes:
pgdata:
# Scale api to 3 instances
# docker compose up --scale api=3 -d
# Activate debug profile
# docker compose --profile debug up -d
Related Resources
Docker Reference
Complete tag & property list
Docker How-To Guides
Step-by-step practical guides
Docker Exercises
Practice what you've learned
More in Docker