Interpolate environment variables in docker-compose.yml
Problem
(I'm creating a fresh issue for this as the old one has accumulated rather a lot of baggage.) It should be possible to pass in environment variables to the value of any\ configuration entry in `docker-compose.yml`. A lot of people want to do it, it's good for portability and I'm satisfied it's not going to cause chaos. I have some reckons. Required variables and optional defaults It's useful to be able to specify that a variable that _must_ be present in the environment, i.e. that Compose will refuse to run if it isn't. However, this will be a pain when you've got lots of them, so it should either be something you explicitly enable, or it should be possible to specify a default value. The MVP implementation does not need to have either feature, but there should be a clear path to implementing both in a backwards-compatible way. Syntax There's a strong case for implementing an established standard, as long as it's not heavyweight - our requirements for functionality are minimal. - POSIX parameter expansion is OK. It has a few too many features, but we could implement a subset of them: - `${VARIABLE}` - outputs empty string if `VARIABLE` is unset - `${VARIABLE-default}` - outputs `default` if `VARIABLE` is unset - `${VARIABLE?}` - errors out if `VARIABLE` is unset https://github.com/docker/compose/pull/845 implemented a Bash-style `${VARIABLE:default}` syntax, which is similar to POSIX parameter expansion but slightly different. - Python's format syntax woul
Error Output
error out - instead, it also results in no expansion:
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Interpolate environment variables in docker-compose.yml
My use case is to allow `$PWD` in `volumes`, so every developer in the team can clone a repo to wherever and paths still get mounted correctly. [code block]
Trust Score
6 verifications
- 1
My use case is to allow `$PWD` in `volumes`, so every developer in the team can
My use case is to allow `$PWD` in `volumes`, so every developer in the team can clone a repo to wherever and paths still get mounted correctly.
Validation
Resolved in docker/compose GitHub issue #1377. Community reactions: 20 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep