Docker服务发现不适用于默认网桥 [英] Docker service discovery does not work with default bridge
问题描述
似乎docker服务发现等功能仅适用于用户定义的网络,而不适用于默认网桥(docker0),但我在文档中未找到任何内容。
Seems like docker service discovery just works with user defined networks and not with default bridge (docker0), but I didn't find anything in the docs.
docker run --rm -d --name c1 alpine sleep 2h
docker run- rm -d --name c2 alpine sleep 2h
docker exec -ti c1 ping c2
它给我 ping:错误的地址'c2'
但是如果我创建自定义桥网络一切正常:
docker网络创建u-bridge
docker run --rm -d --name u1 --net u-bridge高山睡眠2h
docker run --rm -d --name u2- -net u-bridge高山睡眠2h
docker exec -ti u1 ping u2
But if I create a custom bridge network everthing works fine:
docker network create u-bridge
docker run --rm -d --name u1 --net u-bridge alpine sleep 2h
docker run --rm -d --name u2 --net u-bridge alpine sleep 2h
docker exec -ti u1 ping u2
它给我: PING u2(172.18.0.3):56个数据字节(...)
默认的桥接网络不应该有服务发现吗?
Shouldn't default bridge network have service discovery?
推荐答案
默认的容器需要明确链接,认为这是旧版/不推荐使用行为。
Containers on the default bridge need to be explicitly linked, which is considered legacy/deprecated behaviour.
警告:
-link
标志是的不推荐使用的旧功能码头工人
最终可能会被删除。除非您绝对需要继续使用
,否则我们建议您使用用户定义的网络来促进两个容器之间的
通信,而不要使用-link
。用户定义的网络不支持的一项
功能,您可以使用
-link
来实现,它在容器之间共享环境变量。但是,您可以使用其他机制,例如卷,以更可控的方式在容器之间共享环境
变量。
Warning: The
--link
flag is a deprecated legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using--link
. One feature that user-defined networks do not support that you can do with--link
is sharing environmental variables between containers. However, you can use other mechanisms such as volumes to share environment variables between containers in a more controlled way.
用户如您所展示的,应该使用定义的网络。
User defined networks should be used instead, as you have demonstrated.
这篇关于Docker服务发现不适用于默认网桥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!