Not able to connect to network inside docker container


Not able to connect to network inside docker container

I have a CentOS 7 host on which I am running Docker. When I do a ping from my host to, ping was successful whereas same inside a docker container is not working.
From Host
[root@linux1 ~]# ping
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=47 time=31.5 ms
64 bytes from icmp_seq=2 ttl=47 time=31.6 ms
— ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 31.592/31.617/31.643/0.179 ms

From Docker Container (I am using basic ubuntu image):
[root@linux1 ~]# docker run ubuntu ping
PING ( 56(84) bytes of data.
From icmp_seq=1 Destination Host Unreachable
From icmp_seq=2 Destination Host Unreachable
From icmp_seq=3 Destination Host Unreachable
From icmp_seq=4 Destination Host Unreachable
— ping statistics —
6 packets transmitted, 0 received, +4 errors, 100% packet loss, time 5000ms
pipe 4

Any suggestions would be helpful. Thanks


Solution 1:

Restart the Docker daemon on Debian9

service docker restart

and the connections and networks works fine

Solution 2:

I figured out the issue. It is not an issue with the DNS but an issue with the network connection itself inside Docker containers. Drilled down the issue is the default IP assigned to docker0 interface, which conflicted with my network address. Forced docker daemon to assign an IP so that it won’t conflict and my issue is resolved.


Solution 3:

Try this:

docker run --dns= -it ubuntu ping