我想让 docker 容器的 IP 可以从主机访问,就像 VirtualBox 具有的“仅主机网络”一样。
目前,我可以从 docker 容器 ping 通 windows 主机,但反之则不行。
这是我的 Docker 容器配置
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2091 errors:0 dropped:0 overruns:0 frame:0
TX packets:22137 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:176077 (171.9 KiB) TX bytes:3396902 (3.2 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:444 (444.0 B) TX bytes:444 (444.0 B)
这是 Windows 主机
Ethernet adapter vEthernet (Default Switch):
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::9197:4f9c:c12b:a2d4%29
IPv4 Address. . . . . . . . . . . : 172.18.0.1
Subnet Mask . . . . . . . . . . . : 255.255.240.0
Default Gateway . . . . . . . . . :
这是我尝试从容器 ping Windows 主机时得到的结果
/ # ping 172.18.0.1
PING 172.18.0.1 (172.18.0.1): 56 data bytes
64 bytes from 172.18.0.1: seq=0 ttl=37 time=1.369 ms
64 bytes from 172.18.0.1: seq=1 ttl=37 time=1.580 ms
64 bytes from 172.18.0.1: seq=2 ttl=37 time=1.524 ms
64 bytes from 172.18.0.1: seq=3 ttl=37 time=1.416 ms
64 bytes from 172.18.0.1: seq=4 ttl=37 time=1.573 ms
64 bytes from 172.18.0.1: seq=5 ttl=37 time=1.428 ms