How dynamic map service name to ENV var

与世无争的帅哥 提交于 2020-01-17 06:24:05

问题


Example:

my-server:
  image: my-server:latest
  ports:
    - 1234:1234
proxy:
  image: lb:latest
  environment:
    - BACKEND=${VAR}??? # must be resolve as 'my-server'

The server name can be changed to any name, but the proxy has a entry-point script where the variable will be substituted in the BACKEND to config.


回答1:


You can use a .env file to define your variable. This file will be placed in the same directory as your docker-compose.yml file.

When you run docker-compose, it will read this value and use it. Using your example, your .env file would look something like this:

VAR=my-server

and, the line:

- BACKEND=${VAR}??? # must be resolve as 'my-server'

would become just:

- BACKEND=${VAR}

or

BACKEND: ${VAR}


来源:https://stackoverflow.com/questions/42122860/how-dynamic-map-service-name-to-env-var

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!