Profiles help you adjust your Compose application for different environments or use cases by selectively activating services. Services can be assigned to one or more profiles.
This setup means specific services, like those for debugging or development, to be included in a single compose.yml file and activated only as needed.
E.g.,
docker compose --profile db up starts db and adminer services.
Services with a profiles: key only run when you enable that profile.
docker compose --profile db --profile monitor up
Stop a profile: docker compose --profile devcontainer stop
If you have configured a default profile, this will stop that profile as well: docker compose stop
Listing Profiles
List static profiles (but not the real active ones) with : docker compose config --profiles
1
2
3
4
adminer
prometheus
db
some_included_profile_that_is_not_defined_in_this_yml
To inspect the final compose file in a single “flattened” doc, after yaml anchors (&common), extends: blocks, environment variables, profiles and volume definitions have been resolved: docker compose --profile <PROFILE> config
Yaml anchors vs expanded fields:
In a source template, you define a reusable anchor block