Docker container can not ping the outside world - iptables

Viewed 44000

exploring Docker 17.06.

I've installed docker on Centos 7 and created a container. Started the container with the default bridge. I can ping both host adapters, but not the outside world e.g. www.google.com

All advise out there is based on older versions of Docker and it's iptables settings.

I would like to understand how to ping to the outside world, what is required please?

TIA!

5 Answers

In my case restarting docker daemon helped

sudo systemctl restart docker

If iptables is not a reason and if you have no some limitation for change containers network mode - set it to "host" mode. This should solve this issue.

I had a similar problem, an api docker container needed connection to outside, but the others containers not. So my option was add the flag --dns 8.8.8.8 to the docker run command , and with that the container can ping to outside. I consider this a solution for one container, if you need for more containers, maybe other responses are better. Here the documentation. And full line example:

docker run -d --rm -p 8080:8080 --dns 8.8.8.8 <docker-image-name>

where:

  • -d, detach mode for run containers in background
  • --rm, remove containers if is stop (careful if you are testing and maybe you need to inspect logs, with docker logs , don't use it)
  • -p, specify the port ( <host-port> : <container-port> )
  • --dns, the container can resolve internet domains
Related