Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do variable substitution in env_file?

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???

like image 294
chrish Avatar asked Feb 08 '16 19:02

chrish


People also ask

How to quickly replace environment variables in a 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. ...

What is the difference between $variable and $env values?

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.

How do I use multiple environment variables in Linux?

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.

How can I substitute environment variables in Kubernetes configuration files?

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.


1 Answers

Variable substitution is not supported in env_file.

Your options are:

  • use variables in the 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).
  • use host variables by specifying an environment variable without a value (ex: LOCALPATH=), which may be in either the env_file or environment section.
like image 155
dnephin Avatar answered Sep 30 '22 20:09

dnephin