OStack程序员社区-中国程序员成长平台

标题: networking - 覆盖docker网络中--link和--alias之间的区别? [打印本页]

作者: 菜鸟教程小白    时间: 2022-8-3 10:12
标题: networking - 覆盖docker网络中--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.



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



Best Answer-推荐答案


--net-alias之间有两个区别和 --link :

  • --net-alias ,一个容器只有在同一个网络上才能访问另一个容器。也就是说,除了--net-alias foo--net-alias bar ,您需要使用 --net foobar_net 启动两个容器使用 docker network create foobar_net 创建网络后.
  • --net-alias foo , 全部 同一网络中的容器可以通过别名foo 访问容器。 .与 --link , 只有链接的容器 可以使用名称 foo 访问容器.

  • 从历史上看,--link之前创建的 libnetwork以及所有与网络相关的功能。之前 libnetwork ,所有容器都在同一网络中运行 bridge , 和 --link仅将名称添加到 /etc/hosts .然后,添加了自定义网络和 the behavior of --link in user-defined networks was changed .

    另见 Legacy container links有关 --link 的更多信息.

    关于networking - 覆盖docker网络中--link和--alias之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36048897/






    欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4