Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define an environment value witih : in name in docker compose?

I would like to pass an environment variable named ABC:DEF to a container defined in a docker-compose.yml.

How to do it?

If I write in a service definition

environment:
    ABC:DEF: ${ABC:DEF}

I got

ERROR: Invalid interpolation format for "environment" option in service: "${ABC:DEF}"

Edit: The goal of this question is to understand whether it is possible to use environment variables names which contain a : colon and how to properly define that in docker-compose.yml. A discussion what are the alternatives to using the : colon from the view of the "thing" running inside the affected container is not part of the question.

like image 789
alik Avatar asked Oct 20 '18 08:10

alik


People also ask

Can I use environment variables in Docker compose file?

Docker Compose allows us to pass environment variables in via command line or to define them in our shell. However, it's best to keep these values inside the actual Compose file and out of the command line.

How do I set an environment variable in Docker?

Use -e or --env value to set environment variables (default []). If you want to use multiple environments from the command line then before every environment variable use the -e flag. Note: Make sure put the container name after the environment variable, not before that.

How do you name environment variables?

Environment variable names used by the utilities in the Shell and Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore) from the characters defined in Portable Character Set and do not begin with a digit.


1 Answers

Use the following line instead of ABC:DEF: ${ABC:DEF}:

environment:
  POSTGRES_PASSWORD: any-password 

[UPDATE]:

If : cannot be used in environment variables in your system, replace : with __ (double underscore).

Configuration_in _ASP.NET _Core_Reference

So I think that would be something like this:

ABC__DEF: <asp-environment>    
like image 159
Benyamin Jafari Avatar answered Oct 07 '22 08:10

Benyamin Jafari