2.6 KiB
| title | description | keywords |
|---|---|---|
| Profiles | Learn about profiles | compose, compose specification, profiles, compose file reference |
With profiles you can define a set of active profiles so your Compose application model is adjusted for various usages and environments.
The services top-level element supports a profiles attribute to define a list of named profiles.
Services without a profiles attribute are always enabled.
A service is ignored by Compose when none of the listed profiles match the active ones, unless the service is
explicitly targeted by a command. In that case its profile is added to the set of active profiles.
Note
All other top-level elements are not affected by
profilesand are always active.
References to other services (by links, extends or shared resource syntax service:xxx) do not
automatically enable a component that would otherwise have been ignored by active profiles. Instead
Compose returns an error.
Illustrative example
services:
foo:
image: foo
bar:
image: bar
profiles:
- test
baz:
image: baz
depends_on:
- bar
profiles:
- test
zot:
image: zot
depends_on:
- bar
profiles:
- debug
In the above example:
- If the Compose application model is parsed with no profile enabled, it only contains the
fooservice. - If the profile
testis enabled, the model contains the servicesbarandbaz, and servicefoo, which is always enabled. - If the profile
debugis enabled, the model contains bothfooandzotservices, but notbarandbaz, and as such the model is invalid regarding thedepends_onconstraint ofzot. - If the profiles
debugandtestare enabled, the model contains all services;foo,bar,bazandzot. - If Compose is executed with
baras the explicit service to run,barand thetestprofile are active even iftestprofile is not enabled. - If Compose is executed with
bazas the explicit service to run, the servicebazand the profiletestare active andbaris pulled in by thedepends_onconstraint. - If Compose is executed with
zotas the explicit service to run, again the model is invalid regarding thedepends_onconstraint ofzot, sincezotandbarhave no commonprofileslisted. - If Compose is executed with
zotas the explicit service to run and profiletestis enabled, profiledebugis automatically enabled and servicebaris pulled in as a dependency starting both serviceszotandbar.
See how you can use profiles in Docker Compose.