I have to create the container with ip 192.168.31.11. So, I used the user-defined bridge network and created mynet as:
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:
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!!.
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. The ping from host to container is successful!!.
I am not able to understand what is stopping the ping to succeed in first case!?.
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. In this Ubuntu machine the ping succeeds!!
the ubuntu case details are as below:
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?
Is that I am missing some thing with docker host?
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. 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. 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. So, host and container are trying to same hw type ether with destination address 192.168.31.0 using Iface ethX and br-xxxx. So unlikely can make this container work with ip 192.168.31.11. ( or need to change the host 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?