Skip to main content

Compose Profiles

Compose profiles are labels on services that make them optional. Services without a profile always start, while profiled services start only when their profile is enabled with --profile or COMPOSE_PROFILES.

Optional services in one file

Profiles let one Compose file describe everything (debug tools, mail catchers, test runners) while a plain docker compose up starts only the core stack. A service can belong to several profiles, and a service with no profiles key is always on.

YAML
services:
payment-api:
image: payment-api:v3.1.0
postgres:
image: postgres:16-alpine
mailhog:
image: mailhog/mailhog
profiles: [email]
adminer:
image: adminer
profiles: [debug, tools]
test-runner:
image: payment-api:v3.1.0
command: ["npm", "run", "test:integration"]
profiles: [ci]

Enabling profiles

Bash
docker compose up -d # api + postgres only
docker compose --profile email up -d # plus mailhog
docker compose --profile debug --profile email up -d # several profiles
COMPOSE_PROFILES=ci docker compose up # via environment variable
docker compose --profile "*" up -d # everything

Naming a profiled service directly, such as docker compose run adminer or docker compose up adminer, enables that service's profile for that command.

Interaction with depends_on

A service cannot depend on a service whose profile is inactive unless both are enabled together, so keep dependencies and dependents in matching profiles or leave the dependency unprofiled.

Tip

Put anything not needed every day behind a profile: admin UIs, load generators, and one-off migration jobs.

Common Mistake

Adding a profile to a service that a core service depends on. The core service then fails to start by default.

Frequently Asked Questions

What problem do profiles solve compared with multiple Compose files?

Profiles keep every service definition in one file and decide at runtime which ones start. That avoids parallel files that drift, while still keeping default startup fast and light.

Does a service without a profile ever get skipped?

No. Unprofiled services always start. When you retrofit profiles onto an existing file, only the services you tag become optional.

How do I enable profiles in CI?

Set COMPOSE_PROFILES=ci in the job environment or pass --profile ci. Both work, and the environment variable is convenient when the command line is fixed.

Found a mistake, an outdated step or a broken link?