[root@guanvps ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [root@guanvps ~]# uname -a Linux guanvps 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux [root@guanvps ~]# docker --version Docker version 17.09.1-ce, build 19e2cf6
先容器ping下1.1.1.1发现不可达
1 2 3 4
[root@guanvps ~]# docker exec -ti mysql ping 1.1.1.1 PING 1.1.1.1 (1.1.1.1): 56 data bytes ^C--- 1.1.1.1 ping statistics --- 3 packets transmitted, 0 packets received, 100% packet loss
给lo回环网卡添加上它
1
[root@guanvps ~]# ip addr add 1.1.1.1/32 dev lo:1
然后用容器ping下这个地址
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@guanvps ~]# docker exec -ti mysql ping 1.1.1.1 PING 1.1.1.1 (1.1.1.1): 56 data bytes 64 bytes from 1.1.1.1: icmp_seq=0 ttl=64 time=0.131 ms 64 bytes from 1.1.1.1: icmp_seq=1 ttl=64 time=0.058 ms 64 bytes from 1.1.1.1: icmp_seq=2 ttl=64 time=0.078 ms 64 bytes from 1.1.1.1: icmp_seq=3 ttl=64 time=0.090 ms 64 bytes from 1.1.1.1: icmp_seq=4 ttl=64 time=0.115 ms 64 bytes from 1.1.1.1: icmp_seq=5 ttl=64 time=0.088 ms 64 bytes from 1.1.1.1: icmp_seq=6 ttl=64 time=0.146 ms 64 bytes from 1.1.1.1: icmp_seq=7 ttl=64 time=0.081 ms ^C--- 1.1.1.1 ping statistics --- 8 packets transmitted, 8 packets received, 0% packet loss round-trip min/avg/max/stddev = 0.058/0.098/0.146/0.028 ms