File: compose/environment-variables.md
How to declare default values for environment values substitution in situations where the .env file cannot be used?
If I understand your question correctly, you can use shell parameter substitution.
Your compose file would look like:
version: '3.1'
services:
lb:
image: nginx:latest
environment:
PASSWORD: "${PASS:-secret}"
In the container, set $PASSWORD with the value of $PASS or default to secret. Then you could use:
PASS=super-secret docker-compose -f docker-compose-2.yml up
Please consider filing a pull request to improve the docs 馃檹
I reckon this can be closed as it's fairly well documented here:
https://docs.docker.com/compose/compose-file/#variable-substitution
as referenced in @waltertross documentation:
For more information, see the Variable substitution section in the Compose file reference.
Closing this ticket due to its age, and the impending refactor. If you think this is in error, feel free to reopen. Thanks!
To be exact, it should be:
version: '3.1'
services:
lb:
image: nginx:latest
environment:
- PASSWORD="${PASS:-secret}"
Note the added dash and an equal sign instead of a colon.
@worp1900:
I reckon this can be closed as it's fairly well documented here:
https://docs.docker.com/compose/compose-file/#variable-substitution
This page no longer has documentation about variable substitution. Is there an updated link?
There's no info about "docker compose default environment variable value" found by google in the documentation. Only this issue was found. Since it's beyond basic bash knowledges, please place it to the compose file docs.
Docs seem to have been restructured by compose file version. This link works:
https://docs.docker.com/compose/compose-file/compose-file-v3/#variable-substitution
Most helpful comment
If I understand your question correctly, you can use shell parameter substitution.
Your compose file would look like:
In the container, set
$PASSWORDwith the value of$PASSor default tosecret. Then you could use:Please consider filing a pull request to improve the docs 馃檹