Optional services can make a Compose project noisy when debugging tools, seed jobs, or local-only helpers start every time the stack starts. Docker Compose profiles keep those services in the same Compose file while starting them only when a named profile is active.
A service without a profiles entry is always part of the default model. A service with profiles: [“debug”] is skipped by normal docker compose up and included when --profile debug or COMPOSE_PROFILES=debug is set.
Profile names should be stable because developers, CI jobs, and runbooks may depend on them. Use profiles for optional runtime services, not for secrets or environment-specific values that should live in env files or deployment configuration.
services: app: image: registry.example.com/team/app:1.0 debug: image: registry.example.com/team/debug-tools:1.0 profiles: ["debug"] command: ["sleep", "infinity"]
$ docker compose config --profiles debug
$ docker compose config --services app
Services without a profiles entry remain enabled by default.
$ docker compose --profile debug config --services debug app
$ docker compose up --detach Container example-stack-app-1 Started
$ docker compose --profile debug up --detach debug Container example-stack-debug-1 Started
$ docker compose --profile debug ps --services app debug