在docker-compose中使用--add-host或extra_hosts [英] Using --add-host or extra_hosts with docker-compose
问题描述
我正在使用 docker-compose
来运行测试环境,该环境由大约5个不同的容器组成。容器间链接和共享卷(从)开始工作非常好。我还向主机公开了一些端口,这很好用。
I am using docker-compose
to run a test environment, that consists of about 5 different containers. The inter-container links and the shared volumes (volumes-from) works wonderfully. I also expose some ports up to the host machine, which works nicely.
我所缺少的是一种将一些真实服务器链接到此环境而无需进行硬编码的方法IP地址。使用 docker run
,您可以使用-add-host
在中添加另一行/ etc / hosts
文件。有什么方法可以与docker-compose做类似的事情吗?
What I am missing is a way to link some of my real servers into this environment, without hardcoding ip address. With docker run
, you could use --add-host
to add another line in your /etc/hosts
file. Is there any way to do something similar with docker-compose?
推荐答案
我有个好消息:这将在Compose 1.3中发布!
I have great news: this will be in Compose 1.3!
我正在这样的当前RC(RC1)中使用它:
I'm using it in the current RC (RC1) like this:
rng:
build: rng
extra_hosts:
seed: 1.2.3.4
tree: 4.3.2.1
这篇关于在docker-compose中使用--add-host或extra_hosts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!