简体   繁体   English

docker 主机和容器中的网络设置使用用户定义的桥接网络,其中从主机到容器的 ping 失败

[英]Network setting in docker host and container using user defined bridge network, where ping fails from host to container

I have to create the container with ip 192.168.31.11.我必须使用 ip 192.168.31.11 创建容器。 So, I used the user-defined bridge network and created mynet as:因此,我使用了用户定义的桥接网络并将 mynet 创建为:

docker network create \
                --driver=bridge \
                --subnet=192.168.31.0/24 \
                --ip-range=192.168.31.0/24 \
                --gateway=192.168.31.1 \
                mynet

Now, using the command现在,使用命令

docker run --network mynet --name ca1 --ip 192.168.31.11 -itd -p 8002:80 -v $PWD:/build sc5

I have created the container.我已经创建了容器。 The docker host has now below ifconfig: docker 主机现在具有以下 ifconfig:

br-426eea85deb3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500  metric 1
        inet 192.168.31.1  netmask 255.255.255.0  **broadcast 192.168.31.255**
        inet6 fe80::42:cfff:fe3e:d01b  prefixlen 64  scopeid 0x20<link>
        ether 02:42:cf:3e:d0:1b  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7  bytes 586 (586.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500  metric 1
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:58:0e:02:97  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500  metric 1
        inet 192.168.31.101  netmask 255.255.255.0  **broadcast 192.168.31.255**
        inet6 fe80::202:6bff:fe21:463c  prefixlen 64  scopeid 0x20<link>
        ether 00:02:6b:21:46:3c  txqueuelen 1000  (Ethernet)
        RX packets 16  bytes 1440 (1.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 65  bytes 3216 (3.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xdf000000-df01ffff

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536  metric 1
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 509  bytes 37544 (36.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 509  bytes 37544 (36.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethda02539: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500  metric 1
        inet6 fe80::f072:a4ff:fe51:18bb  prefixlen 64  scopeid 0x20<link>
        ether f2:72:a4:51:18:bb  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14  bytes 1172 (1.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

but, when I do ping to container from host to container the ping fails.!.但是,当我从主机到容器对容器执行 ping 操作时,ping 失败。!。

But when I change the docker host network setting using /etc/sysconfig/network , the host ip from 192.168.31.101 to 192.168.11.101 .但是当我使用/etc/sysconfig/network更改 docker 主机网络设置时,主机 ip 从192.168.31.101192.168.11.101 The ping from host to container is successful.!.从主机到容器的 ping 成功。!。

I am not able to understand what is stopping the ping to succeed in first case?..我无法理解在第一种情况下阻止 ping 成功的原因是什么?..

I have tried the same on ubuntu machine by creating the mynet with same broadcast xx.xx.xx.xx that of host and container br-xxxx broacast.我在 ubuntu 机器上尝试了相同的方法,方法是创建具有与主机和容器 br-xxxx 广播相同的广播 xx.xx.xx.xx 的 mynet。 In this Ubuntu machine the ping succeeds!!在这台 Ubuntu 机器上 ping 成功!!

the ubuntu case details are as below: ubuntu 机箱详细信息如下:

ifconfig:如果配置:

br-7b1ed572fe95: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.2  netmask 255.255.255.0  **broadcast 10.0.2.255**
        inet6 fe80::42:bff:fe9d:d6eb  prefixlen 64  scopeid 0x20<link>
        ether 02:42:0b:9d:d6:eb  txqueuelen 0  (Ethernet)
        RX packets 97  bytes 12767 (12.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 61  bytes 6739 (6.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:11:f0:da:29  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  **broadcast 10.0.2.255**
        inet6 fe80::365a:ddd:b83c:4abe  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:82:79:c2  txqueuelen 1000  (Ethernet)
        RX packets 14188  bytes 15705468 (15.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3415  bytes 264989 (264.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1727  bytes 141367 (141.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1727  bytes 141367 (141.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth11ef32e: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::b014:feff:feaa:cea3  prefixlen 64  scopeid 0x20<link>
        ether b2:14:fe:aa:ce:a3  txqueuelen 0  (Ethernet)
        RX packets 97  bytes 14125 (14.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 87  bytes 9899 (9.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I am confused and no idea why ping fails in 192.xx.xx.xx case that succeeds in case of Ubuntu on Windows VM?我很困惑,不知道为什么在 Windows VM 上的 Ubuntu 情况下 192.xx.xx.xx 情况下 ping 会失败?

Is that I am missing some thing with docker host?我是否缺少 docker 主机的一些东西?

Any help or guidance will much appreciated.任何帮助或指导将不胜感激。 Please let me know if more information or details needed further to understand the same to suggest on something.请让我知道是否需要更多信息或细节来进一步理解相同的建议。 Thanks,谢谢,

I have checked thoroughly, the VM has managed the routing with same destination address and with enpxsx and br-xxx.我已经彻底检查过,VM 已经使用相同的目标地址以及 enpxsx 和 br-xxx 管理路由。 But on my hardware, the routing is getting clashed when have same destination address in route.但是在我的硬件上,当路由中具有相同的目标地址时,路由会发生冲突。

The route command details:路由命令详细信息:

$route -vn
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.31.31        0.0.0.0         UG    100    0        0 enp0s3
192.168.31.0        0.0.0.0         255.255.255.0   U     0      0        0 br-7b1ed572fe95
192.168.31.0        0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 enp0s3
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0

So, there is 192.168.31.0 destination with enp0s3 and br-xxxx too.所以,192.168.31.0 目的地也有 enp0s3 和 br-xxxx。 Which blocking the routing.!.哪个阻塞了路由.!. To verify the same I have created another user defined bridge network with 192.168.11 .x setting and it works as expected.为了验证这一点,我创建了另一个具有192.168.11 .x 设置的用户定义的桥接网络,它按预期工作。 So, host and container are trying to same hw type ether with destination address 192.168.31.0 using Iface ethX and br-xxxx .因此,主机和容器正在尝试使用Iface ethX 和 br-xxxx与目标地址 192.168.31.0 相同的硬件类型 ether。 So unlikely can make this container work with ip 192.168.31.11 .所以不太可能使这个容器与 ip 192.168.31.11一起工作。 ( or need to change the host ip 192.168.11.X ) (或者需要改主机ip 192.168.11.X

Or is there any thing I can do to make work, with same 192.168.31.x ip on host and container(s) having 192.168.31.x?或者有什么我可以做的事情,在主机和容器上使用相同的 192.168.31.x ip 192.168.31.x?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM