Skip to content
tezvyn:

Docker Compose Profiles: Activate Service Groups

Source: docs.docker.comHardHow cards are made

Docker Compose profiles let you toggle groups of services on or off within a single compose.yaml file. Use it to separate your core app from debugging utilities or to define a "local dev" setup versus a "CI" setup.

Why it exists

To avoid managing multiple, slightly different compose.yaml files for various scenarios like local development, debugging, and CI. Profiles allow you to define all these variations within a single, authoritative file, reducing duplication and complexity.

The mental model

Think of profiles as tags you apply to your services. By default, Compose only starts untagged services. You can then tell Compose, "run the untagged services AND any services tagged 'debug'". This lets you selectively activate optional groups of services on top of your base configuration.

How it works

In your compose.yaml, add a profiles list to any service you want to make optional (e.g., profiles: ["debug"]). When you run docker compose up, only services without a profiles key will start. To activate a profile, use the flag: docker compose --profile debug up. This command starts all un-profiled services plus any services matching the debug profile. You can activate multiple profiles at once, and a service will run if any of its assigned profiles are active.

When to use it

Profiles are ideal for separating optional services from your core application stack. Three common use cases: first, adding debugging tools like a database GUI or a log analyzer that you only need occasionally; second, defining environment-specific setups, like a dev profile that mounts source code volumes for hot-reloading; third, running mock services for isolated testing in a CI pipeline.

When not to use it

For fundamentally different application stacks or major configuration changes that affect most services, using separate compose.yaml files (e.g., compose.ci.yaml) and merging them is often clearer. Profiles are best for enabling or disabling subsets of services within a single, coherent application, not for managing entirely separate deployments.

One canonical example

A web app might have a backend and db service with no profile assigned. A phpmyadmin service for database inspection could be assigned profiles: ["debug"]. Running docker compose up starts only the backend and db. To also run the admin tool, you would execute docker compose --profile debug up, which starts backend, db, AND phpmyadmin.

Interview question

What is the primary benefit of using Docker Compose profiles?

  • a.To manage configurations for fundamentally different application stacks within a single compose.yaml file.
  • b.To apply major configuration changes, like resource limits or network settings, uniformly across the majority of services in a project.
  • c.To define and selectively activate optional groups of services, such as debugging tools or environment-specific setups, from a unified compose.yaml.Correct
  • d.To ensure that all services defined in the compose.yaml file are always launched together, simplifying deployment.
Why?

Profiles are designed to enable or disable subsets of services (e.g., debugging tools, dev-specific setups) within a single compose.yaml file, reducing complexity. Option A describes a scenario where separate compose.yaml files are explicitly recommended instead of profiles.

Just read this? Test yourself on what you have been reading.

Read the original → docs.docker.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on docker — each one lists the topics its interview covers.

See open roles