我正在试验新的docker网络功能.我使用容器链接将旧设置迁移到新的网桥网络;到目前为止,我已经建立了专用的桥接网络并在同一主机上的多个容器之间运行.
现在,我正在寻找一种方法来为同一容器复制多个链接别名.
说,我有一个名为myBox的容器,该容器加入了docker网络.我想拥有与myServer相同的容器.
使用链接,我将简单地设置两个具有不同别名的链接.
是否有使用Docker网络实现此目标的方法?
We’d like a container to be able to join a network under different names,not just the container name.
这也将有助于Docker组成:请参阅docker/compose issue 2312.
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?
This is now done in 1.6.0 (RC1 is out)
注意:Compose 1.5中引入的实验性标志–x-networking和–x-network-driver已被删除.
参见PR 19242和docker network connect
:
--alias
option can be used to resolve the container by another name in the network being connected to.
$docker network connect --alias db --alias MysqL multi-host-network container2
也:
You can use –link option to link another container with a prefered alias
$docker network connect --link container1:c1 multi-host-network container2