使用图添加到容器的 /etc/hosts?
Add to container's /etc/hosts using Fig?
我正在尝试配置 fig
以便我可以在不指定完全限定域名的情况下连接到我的数据库服务器。数据库在裸机上 运行(不在 docker 中)。在主机上,glinda.local
在 /etc/hosts
中指定,我希望容器模仿这种行为(尽管不依赖于主机的配置)。
我在 github 上找到了 this suggestion,但它失败了,因为 /etc/hosts
在只读文件系统上。
所以问题仍然存在,如何在我的 docker 容器中将 glinda.local
从 fig.yml
添加到 /etc/hosts
?
是什么让您认为 /etc/hosts
是只读的?以下适用于 Docker 1.5:
$ docker run -it debian
root@0989fd55e8fa:/# echo "127.0.0.1 test" >> /etc/hosts
root@0989fd55e8fa:/# ping test
PING test (127.0.0.1): 48 data bytes
56 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.078 ms
56 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.068 ms
^C--- test ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.068/0.073/0.078/0.000 ms
你是说这对你不起作用吗?如果上述方法有效,您应该能够将您需要的内容添加到入口点脚本中。
从 Docker v1.3.1(我认为)开始,您可以在 docker run
中使用 --add-host
选项。不幸的是,此选项尚未合并到 fig:master,但有 a PR with it。合并(或使用该分支)时,您应该能够以这种方式使用它:
extra_hosts
Add hostname mappings. Use the same values as the docker client
--add-hosts parameter.
> extra_hosts:
> - docker: 162.242.195.82
> - fig: 50.31.209.229
An entry with the ip address and hostname will be created in
/etc/hosts inside containers for this service, e.g:
> 162.242.195.82 docker
> 50.31.209.229 fig
我正在尝试配置 fig
以便我可以在不指定完全限定域名的情况下连接到我的数据库服务器。数据库在裸机上 运行(不在 docker 中)。在主机上,glinda.local
在 /etc/hosts
中指定,我希望容器模仿这种行为(尽管不依赖于主机的配置)。
我在 github 上找到了 this suggestion,但它失败了,因为 /etc/hosts
在只读文件系统上。
所以问题仍然存在,如何在我的 docker 容器中将 glinda.local
从 fig.yml
添加到 /etc/hosts
?
是什么让您认为 /etc/hosts
是只读的?以下适用于 Docker 1.5:
$ docker run -it debian
root@0989fd55e8fa:/# echo "127.0.0.1 test" >> /etc/hosts
root@0989fd55e8fa:/# ping test
PING test (127.0.0.1): 48 data bytes
56 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.078 ms
56 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.068 ms
^C--- test ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.068/0.073/0.078/0.000 ms
你是说这对你不起作用吗?如果上述方法有效,您应该能够将您需要的内容添加到入口点脚本中。
从 Docker v1.3.1(我认为)开始,您可以在 docker run
中使用 --add-host
选项。不幸的是,此选项尚未合并到 fig:master,但有 a PR with it。合并(或使用该分支)时,您应该能够以这种方式使用它:
extra_hosts
Add hostname mappings. Use the same values as the docker client --add-hosts parameter.
> extra_hosts:
> - docker: 162.242.195.82
> - fig: 50.31.209.229
An entry with the ip address and hostname will be created in /etc/hosts inside containers for this service, e.g:
> 162.242.195.82 docker
> 50.31.209.229 fig