Docker Community Forums

Share and learn in the Docker community.

Communication between containers and wider world

(MingCHEN) #1

in a container, when initially created from a image, I cannot successfully Ping or or those kind of outside Internet. According to the offical docs of docker, the newly created containers could get access to the Internet by default. BUT, i don’t know why my containers couldn’t Ping outside internet.
Details of attempts:

  •  (1) I tried Pinging the other containers' ip address, it worked.
  •  (2) I tried Pinging docker0's ip address, it worked.
  •  (3) I tried Pinging the host computer's ip address, it worked.
  •  (4) i guess the problem is resulted from **iptables**, the firewall in Ubuntu,

after executing “#iptables -t nat --iist”:

Anybody knows the solution?

(David Maze) #2

Does DNS work (host DNS, using a known external DNS server (host TCP (curl Do you have a specific reason to need to send ICMP traffic? Does your external network block it?

(MingCHEN) #3

(1) DNS works; you can see my dns configuration in the bottom picture.
(2) i typed command “# curl”, because google is not available without VPN, however, Baidu is always regarded as Chinese Google.
You can see the result in the bottom picture.
(3) As for my reason, I wanna use Docker to build a spark swarm to train CNN, which might be used in the later experiment, related to cloud robots.If I build a container from a basic spark image, I need the container to get access to Internet to “apt-get install” some widgets or updates. SO, the container should be able to connect the Internet.
(4) I don’t think my external Internet has blocked the container, because my host computer could ping the container.


(David Maze) #4

So it looks like you can make outbound HTTP connections. What problem are you having?

If you’re physically located in China, I wouldn’t be surprised if you couldn’t reach Google’s DNS servers and without going through some sort of proxy network, and telling Docker to use them globally will probably cause problems.

“Ping a container” isn’t really a meaningful operation, and in any case, trying to contact a container from your host system never contacts anything off your system at all.

(MingCHEN) #5

My problem is that I couldn’t “apt-get install” or “apt-get update” successfully in a specific container, such as cloud1 in the following screenshots.
If I use “apt-get update”, then I will get the result of “0% [connecting to…]” as picture1, after about 80 seconds (I used the stopwatch to count time), the terminal window shows the error info as picture2
In addition, I added the DNS of my city,Shenzhen, in the DNS configuration as picrture3, including Google’s, but I couldn’t Ping the outside Internet from a container either.
You might have the question about apt sources which have been modified by me. I replaced the offical Ubuntu apt sources with the popular ubuntu apt sources, like 163’s, UTSC’s, in China. It’s ok for me to use those two apt sources because I could “apt-install” other widgets or softwares in the host computer.

(since the new user could only post 1 picture 1 time, I will reply in the following “REPLY”, so as picture3)


(MingCHEN) #6


(MingCHEN) #7


(MingCHEN) #8

Dear all,
The issue has been resolved by myself recently. Totally, i’ve been fighting this problem on and off for almost one week, fortunately, some posts in github, stackoverflow, askubuntu, etc, gave me insights. Hope my way would be helpful to you.
Step1: Check the DNS server you’re using through typing:
mingchen@mingchen-HP:~$ nm-tool | grep DNS
In my terminal, I got;

Step2: copy the above DNS server to the '/etc/docker/daemon.json’
$ sudo gedit /etc/docker/daemon.json
just like the following format:

“dns”: [“”,“”,“”, “”,“”]
Step3: restart docker service.
$ sudo service docker restart

Step4: Run a docker container and test it!
The following is my test result:

root@95ce75c5dbc0:/# ping
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=51 time=38.0 ms
64 bytes from icmp_seq=2 ttl=51 time=37.7 ms
64 bytes from icmp_seq=3 ttl=51 time=37.8 ms

Step5; Hope my post is helpful to you.

Cannot connect to the Docker daemon. Is the docker daemon running on this host?