Question:
in a container, when initially created from a image, I cannot successfully Ping google.com or baidu.com 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,
Does DNS work (host google.com)? DNS, using a known external DNS server (host google.com 8.8.8.8)? TCP (curl http://google.com/)? Do you have a specific reason to need to send ICMP traffic? Does your external network block it?
(1) DNS works; you can see my dns configuration in the bottom picture.
(2) i typed command “# curl https://baidu.com”, 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.
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 8.8.8.8 and 8.8.4.4 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.
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.
picture1
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;
DNS: 127.0.0.1
DNS: 8.8.8.8
DNS: 172.20.1.4
DNS: 172.20.1.6
Step2: copy the above DNS server to the '/etc/docker/daemon.json’ $ sudo gedit /etc/docker/daemon.json
just like the following format:
Step4: Run a docker container and test it!
The following is my test result:
root@95ce75c5dbc0:/# ping baidu.com
PING baidu.com (123.125.114.144) 56(84) bytes of data.
64 bytes from 123.125.114.144: icmp_seq=1 ttl=51 time=38.0 ms
64 bytes from 123.125.114.144: icmp_seq=2 ttl=51 time=37.7 ms
64 bytes from 123.125.114.144: icmp_seq=3 ttl=51 time=37.8 ms