网络 – 覆盖码头网络中的–link和–alias之间的区别?

前端之家收集整理的这篇文章主要介绍了网络 – 覆盖码头网络中的–link和–alias之间的区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在阅读this官方Docker 0.10.3文档(此时,它仍在分支中)并且它说:

--net-alias=ALIAS

In addition to –name as described above,a container is discovered by one or more of its configured –net-alias (or –alias in docker network connect command) within the user-defined network. The embedded DNS server maintains the mapping between all of the container aliases and its IP address on a specific user-defined network. A container can have different aliases in different networks by using the –alias option in docker network connect command.

--link=CONTAINER_NAME:ALIAS

Using this option as you run a container gives the embedded DNS an extra entry named ALIAS that points to the IP address of the container identified by CONTAINER_NAME. When using –link the embedded DNS will guarantee that localized lookup result only on that container where the –link is used. This lets processes inside the new container connect to container without without having to know its name or IP.

来自一个容器的网络别名实际上是来自同一网络中第二个容器的链接吗?

最佳答案
–net-alias和–link之间有两点不同:

>使用–net-alias,只有当一个容器位于同一网络上时,才能访问另一个容器.换句话说,除了–net-alias foo和–net-alias bar之外,在使用docker network create foobar_net创建网络后,需要使用–net foobar_net启动两个容器.
>使用–net-alias foo,同一网络中的所有容器都可以使用其别名foo到达容器.使用–link,只有链接的容器可以使用名称foo到达容器.

从历史上看,–link是在libnetwork和所有与网络相关的功能之前创建的.在libnetwork之前,所有容器都在同一个网桥中运行,并且 – 仅将链接添加到/ etc / hosts.然后,添加自定义网络和the behavior of --link in user-defined networks was changed.

有关–link的更多信息,另请参见Legacy container links.

猜你在找的Docker相关文章