Use Docker Compose profiles when your application needs a small default stack plus optional local-only services. Services with no profiles entry start normally; services assigned to a profile are included only when that profile is activated or the service is explicitly targeted. This lets one compose.yaml replace several near-duplicate files without making every developer start every tool.
Keep the application and the dependencies it cannot operate without outside profiles. Put convenience services such as database browsers, email catchers, temporary test runners, and debugging tools behind named profiles. Docker documents that unprofiled services are always started, while profiled services are ignored unless their profile is active. Docker’s Compose profiles guide
A practical mental model
- No profile: part of the default application stack.
- One or more profiles: optional unless a matching profile is enabled.
- Active profile: includes every service assigned to that profile when you run
up. - Explicitly targeted service: can run even if its profile is not enabled, but this does not enable every peer service using that same profile.
Profiles are a selection mechanism, not an isolation or security feature. They do not protect secrets, restrict network access, or turn a development file into a production deployment design.

An illustrative compose.yaml layout
The following is an illustrative reconstruction. Replace image names, ports, environment variables, and commands with values appropriate for your application. The important part is the placement of each profiles entry.
services:
app:
image: example/my-app:latest
depends_on:
db:
condition: service_started
ports:
- "8080:8080"
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: local-dev-password
volumes:
- db-data:/var/lib/postgresql/data
adminer:
image: adminer:latest
profiles: ["tools"]
depends_on:
- db
ports:
- "8081:8080"
mailpit:
image: axllent/mailpit:latest
profiles: ["tools"]
ports:
- "8025:8025"
test:
image: example/my-app:latest
profiles: ["test"]
depends_on:
- db
command: ./run-tests.sh
migrate:
image: example/my-app:latest
profiles: ["migrate"]
depends_on:
- db
command: ./run-migrations.sh
volumes:
db-data:Here, app and db form the normal stack. Activating tools adds both Adminer and Mailpit. The test and migration jobs use separate profiles because starting all tools should not automatically run tests or alter a database.
Start only the services you need
# Start the default stack: app and db
docker compose up -d
# Start the default stack plus Adminer and Mailpit
docker compose --profile tools up -d
# Start the default stack plus more than one optional group
docker compose --profile tools --profile test up -d
# Use an environment variable instead of repeated --profile flags
COMPOSE_PROFILES=tools,test docker compose up -dCOMPOSE_PROFILES accepts a comma-separated set of profile names. Use your shell’s usual syntax for setting environment variables; the inline form shown above is common in POSIX-compatible shells and is not the same syntax in every Windows shell. Docker documents both repeated --profile flags and COMPOSE_PROFILES. Compose environment variable reference
Why explicit targeting surprises people
If you explicitly run a profiled service, Compose can run that service without first enabling its profile. For example, docker compose run --rm migrate runs the migration service and starts its declared dependency, db, if needed. It does not start Adminer or Mailpit merely because they are also optional services elsewhere in the file.
This is useful for one-off tasks. It also means profile membership is not a dependency group. Declare actual dependencies with depends_on, and do not assume services sharing a profile will appear together when one of them is targeted.
Design dependencies so profiles remain predictable
Before assigning a service to a profile, ask whether another service truly needs it to start. If the answer is yes for normal application operation, leave that dependency unprofiled. In the example, the database stays outside profiles because both the application and optional jobs use it.
A service that references another service which has been ignored because its profile is inactive can produce a Compose error. Do not create a default service that depends on an optional profiled service unless that profile will always be enabled for the command being used. The Compose file reference describes this caveat: ignored services are not automatically activated just because another service refers to them. Compose profiles reference
Verify the plan before relying on it
- List the profile names defined by the file:
docker compose config --profiles. - Start the default stack with
docker compose up -d. - Check what is actually running with
docker compose ps. - Enable one profile, run
docker compose psagain, and confirm that only the intended optional services were added. - Run a one-off job explicitly, such as
docker compose run --rm migrate, only after confirming its command and database target are appropriate.
docker compose config --profiles is a low-risk check for names and spelling, not a runtime test. It cannot confirm that an image can be pulled, a host port is free, credentials work, a database is healthy, or an application dependency is logically correct. The command is documented in the docker compose config reference.
Use profiles for optional local components, not essential production behavior
Profiles work best for development, troubleshooting, administration, and test components that are useful but not required every time. Keep a short list of profile names in the repository README and give each profile a narrow purpose. Names such as tools, test, and migrate communicate more than a catch-all profile that quietly starts unrelated services.
For production, use configuration designed for that environment, supply secrets through an appropriate secret-management process, and review which services are required. A profile can reduce local clutter; it is not a substitute for access controls, separate deployment configuration, or operational safeguards.





