Profiles
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.
メモ
All other top-level elements are not affected by
profiles
and 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:
web:
image: web_image
test_lib:
image: test_lib_image
profiles:
- test
coverage_lib:
image: coverage_lib_image
depends_on:
- test_lib
profiles:
- test
debug_lib:
image: debug_lib_image
depends_on:
- test_lib
profiles:
- debug
In the above example:
- If the Compose application model is parsed with no profile enabled, it only contains the
web
service. - If the profile
test
is enabled, the model contains the servicestest_lib
andcoverage_lib
, and serviceweb
, which is always enabled. - If the profile
debug
is enabled, the model contains bothweb
anddebug_lib
services, but nottest_lib
andcoverage_lib
, and as such the model is invalid regarding thedepends_on
constraint ofdebug_lib
. - If the profiles
debug
andtest
are enabled, the model contains all services;web
,test_lib
,coverage_lib
anddebug_lib
. - If Compose is executed with
test_lib
as the explicit service to run,test_lib
and thetest
profile are active even iftest
profile is not enabled. - If Compose is executed with
coverage_lib
as the explicit service to run, the servicecoverage_lib
and the profiletest
are active andtest_lib
is pulled in by thedepends_on
constraint. - If Compose is executed with
debug_lib
as the explicit service to run, again the model is invalid regarding thedepends_on
constraint ofdebug_lib
, sincedebug_lib
andtest_lib
have no commonprofiles
listed. - If Compose is executed with
debug_lib
as the explicit service to run and profiletest
is enabled, profiledebug
is automatically enabled and servicetest_lib
is pulled in as a dependency starting both servicesdebug_lib
andtest_lib
.
See how you can use profiles
in
Docker Compose.