将Docker容器以两个不同的名称添加到网络 [英] Add docker container to network under two different names
问题描述
我正在尝试新的docker网络功能。我使用容器链接将旧设置迁移到新的网桥网络;到目前为止,我已经建立了专用的桥接网络并在同一主机上的多个容器之间运行。
现在,我正在寻找一种方法来为同一容器复制多个链接别名。
I am experimenting with the new docker networking feature. I migrated my old setup using container links to the new bridge network; so far, I have my dedicated bridge network up and running among multiple containers on the same host.
Now I am looking for a means to replicate multiple link aliases for the same container.
说,我有一个名为 myBox
的容器,该容器加入了docker网络。我想拥有与 myServer
相同的容器。
使用链接,我只需设置两个具有不同别名的链接。
是否有使用docker网络实现此目的的方法?
Say, I have a container named myBox
that joins the docker network. I want to have the same container also reachable as myServer
.
Using links, I would simply set up two links with different aliases.
Is there a means to achieve this using docker networking?
推荐答案
我们希望容器能够以不同的名称(不仅仅是容器名称)加入网络。
We'd like a container to be able to join a network under different names, not just the container name.
这也将帮助 docker组成
:参见 docker /撰写问题2312 。
使用
-x网络
docker-compose 1.5(docker-engine 1.9)中的功能,是否可以在不事先知道容器名称的情况下将添加到 / etc / hosts
机智是否使用container_name
指令?
When using the
--x-networking
feature in docker-compose 1.5 (docker-engine 1.9), is it possible to get a "simple name" added to/etc/hosts
without knowing the container name beforehand and without using thecontainer_name
directive?
现在已在1.6.0中完成(RC1已退出)
This is now done in 1.6.0 (RC1 is out)
请参见 联网撰写
注意:Compose 1.5中引入的实验性标志-x-networking
和-x-network-driver
,已被删除。
Note: The experimental flags --x-networking
and --x-network-driver
, introduced in Compose 1.5, have been removed.
请参见 PR 19242 和 docker network connect
:
-别名
选项可用于解析
$ docker network connect --alias db --alias mysql multi-host-network container2
也:
您可以使用--link选项链接另一个具有首选别名的容器
You can use --link option to link another container with a prefered alias
$ docker network connect --link container1:c1 multi-host-network container2
这篇关于将Docker容器以两个不同的名称添加到网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!