将 --add-host 或 extra_hosts 与 docker-compose 一起使用 [英] Using --add-host or extra_hosts with docker-compose

查看:38
本文介绍了将 --add-host 或 extra_hosts 与 docker-compose 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 docker-compose 来运行一个测试环境,该环境由大约 5 个不同的容器组成.容器间链接和共享卷(volumes-from)工作得非常好.我还向主机公开了一些端口,效果很好.

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

这篇关于将 --add-host 或 extra_hosts 与 docker-compose 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆