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???
How to quickly replace environment variables in a file 1 EnvSubst. The envsubst is part of the gettext internationalization ( i18n) and localization ( l10n) project for unix. 2 Example. Let’s say, we have an existing configuration file, that want to give to someone or use with a bot. ... 3 Conclusion. ... 4 Sources. ...
Values set in the shell environment override those set in the .env file. The .env file feature only works when you use the docker-compose up command and does not work with docker stack deploy. Both $VARIABLE and $ {VARIABLE} syntax are supported.
If you have multiple environment variables, you can substitute them by adding them to a default environment variable file named .env or by providing a path to your environment variables file using the --env-file command line option. Your configuration options can contain environment variables.
Well as it turns out, there already is a good solution and it is called envsubst. We can use envsubst to substitute environment variable placeholders inside configuration files and we can even pipe it into other commands like Kubernetes' kubectl.
Variable substitution is not supported in env_file.
Your options are:
environment:
section (although you wont be able to do your example because setting a value in environment
only sets it for the container environment, and substitution happens on the host).LOCALPATH=
), which may be in either the env_file or environment section.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With