16

I am using docker-compose and I want my env_file to have variable subsitution. I would like to define one variable in the file and then use it in other variables:

APP_ENV=dev-foo
LOCALPATH=/tmp/builddir/${APP_ENV}
[email protected]:some-org/${APP_ENV}

What is the supported form of variable substitutions in env_file???

1 Answer 1

2

Variable substitution is now supported in docker compose

The syntax is similar to shell substitution.

Direct substitution

${VAR} -> value of VAR

Default value

${VAR:-default} -> value of VAR if set and non-empty, otherwise default
${VAR-default} -> value of VAR if set, otherwise default

Required value

${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

Alternative value

${VAR:+replacement} -> replacement if VAR is set and non-empty, otherwise empty
${VAR+replacement} -> replacement if VAR is set, otherwise empty

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.