以两个不同的名称将 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 compose
:参见docker/compose issue 2312.
在 docker-compose 1.5 (docker-engine 1.9) 中使用 --x-networking
功能时,是否可以将简单名称"添加到 /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 中的网络"
注意: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 网络连接
:
See PR 19242 and docker network connect
:
--alias
选项可用于通过正在连接的网络中的另一个名称解析容器.
--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
还有:
您可以使用 --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屋!