如何将服务名称动态映射到ENV var [英] How dynamic map service name to ENV var
本文介绍了如何将服务名称动态映射到ENV var的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:
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.
推荐答案
您可以使用 .env
文件来定义变量。该文件将与您的 docker-compose.yml
文件放置在同一目录中。
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.
运行 docker-compose
时,它将读取并使用该值。使用您的示例,您的 .env
文件看起来像这样:
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
,然后一行:
-BACKEND = $ {VAR} ??? #必须解析为我的服务器
将变为公正:
- BACKEND=${VAR}
或
BACKEND: ${VAR}
这篇关于如何将服务名称动态映射到ENV var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文