docker network create --driver bridge network1
docker run -itd --name docker1 --network network1 busybox
docker run -itd --name docker2 --network network1 busybox
docker exec -it docker1 /bin/bash
现在在docker1中,我可以ping docker2
/ # ping docker2
PING docker2 (172.19.0.3): 56 data bytes
64 bytes from 172.19.0.3: seq=0 ttl=64 time=0.056 ms
我认为此条目已添加到/ etc / hosts中,但它不是
/ # cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
172.19.0.2 841c0dc99115
docker1如何知道docker2的ip地址?
答案 0 :(得分:2)
Docker通过内部DNS服务器解析名称,Docker守护程序使用该服务器,您可以cat /etc/resolv.conf
查看dns地址,了解更多内容,您可以阅读here