Values in a Compose file can be set by variables and interpolated at runtime. Compose files use a Bash-like syntax ${VARIABLE}
. Both $VARIABLE
and ${VARIABLE}
syntax is supported.
For braced expressions, the following formats are supported:
${VAR}
-> value of VAR
${VAR:-default}
-> value of VAR
if set and non-empty, otherwise default
${VAR-default}
-> value of VAR
if set, otherwise default
${VAR:?error}
-> value of VAR
if set and non-empty, otherwise exit with error${VAR?error}
-> value of VAR
if set, otherwise exit with error${VAR:+replacement}
-> replacement
if VAR
is set and non-empty, otherwise empty${VAR+replacement}
-> replacement
if VAR
is set, otherwise emptyInterpolation can also be nested:
${VARIABLE:-${FOO}}
${VARIABLE?$FOO}
${VARIABLE:-${FOO:-default}}
Other extended shell-style features, such as ${VARIABLE/foo/bar}
, are not supported by Compose.
Compose processes any string following a $
sign as long as it makes it a valid variable definition - either an alphanumeric name ([_a-zA-Z][_a-zA-Z0-9]*
) or a braced string starting with ${
. In other circumstances, it will be preserved without attempting to interpolate a value.
You can use a $$
(double-dollar sign) when your configuration needs a literal dollar sign. This also prevents Compose from interpolating a value, so a $$
allows you to refer to environment variables that you don't want processed by Compose.
If Compose can't resolve a substituted variable and no default value is defined, it displays a warning and substitutes the variable with an empty string.
As any values in a Compose file can be interpolated with variable substitution, including compact string notation for complex elements, interpolation is applied before a merge on a per-file basis.
Interpolation applies only to YAML values, not to keys. For the few places where keys are actually arbitrary user-defined strings, such as labels or environment, an alternate equal sign syntax must be used for interpolation to apply. For example:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4