我创建了一个名为docker-br0:
[root@att ~]# docker network list
NETWORK ID NAME DRIVER SCOPE
eb92c719d431 docker-br0 bridge local
...
我现在运行两个容器ubuntu01并ubuntu02附加在docker-br0:
docker run -itd --name ubuntu01 --network docker-br0 ubuntu /bin/bash
docker run -itd --name ubuntu02 --network docker-br0 ubuntu /bin/bash
现在在它们中,他们可以使用容器名称相互 ping 通:
root@d4b349ad46db:/# ping ubuntu01
PING ubuntu01 (172.18.0.2) 56(84) bytes of data.
64 bytes from ubuntu01.docker-br0 (172.18.0.2): icmp_seq=1 ttl=64 time=0.095 ms
64 bytes from ubuntu01.docker-br0 (172.18.0.2): icmp_seq=2 ttl=64 time=0.079 ms
和
root@3a2769dd2576:/# ping ubuntu02
PING ubuntu02 (172.18.0.3) 56(84) bytes of data.
64 bytes from ubuntu02.docker-br0 (172.18.0.3): icmp_seq=1 ttl=64 time=0.135 ms
我的问题是,一个特殊的容器怎么能不能映射其他容器的名称-IP?
在ubuntu02(或utbun01)/etc/hosts文件中,它只添加了自己的 IP 地址。
root@d4b349ad46db:/# more /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.3 d4b349ad46db
那么,容器名称 - ip resolve 在哪里?