Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Urgent, need help!! My Docker Container can't access internet

So, simple:

  1. Create a new VM in GCe, choose ubuntu 20.04, and enable the ip_forwarding.
  2. SSH into it, and install docker. Following the official ubuntu installation guide https://docs.docker.com/engine/install/ubuntu 
  3. Then, because GCE VM uses dnsmasq, we need to add manual DNS, as mentioned in the troubleshooting https://docs.docker.com/engine/install/troubleshoot/#dns-resolver-issues
  4. Because GCE VM uses systemd-network, we need to add another entry, related to ip forwarding https://docs.docker.com/engine/install/troubleshoot/#ip-forwarding-problems 
  5. Restart the machine
  6. Run a simple image with network tools `docker run -it praqma/network-multitool bash`
  7. run `curl https://yahoo.com`
  8. run `ping yahoo.com`
  9. run `apk update`
  10. All failed! no Internet!

Why?? please help!

 

Update:

Turned out my shared_vpc is the culprit. When I deploy a VM into a default VPC, the docker container can work normally.

Update2:

The culprit is C3 machine type. If I use E2, then all work fine. Why???

TL;DR;

Docker container can't connect to internet on C3-type instance. But works on E2-type instance.

5 4 2,500
4 REPLIES 4

Hi I get same issue, only with C3 machine type

For me, docker network on mode host working, but bridge not

I may have found the issue the c3 machines by default have a mtu size of 1460 set for their host interface.

Docker by default sets its mtu to 1500:

root@ess-os-7fda8fc:~# ip addr | grep mtu
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc mq state UP group default qlen 1000
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
7: vethe49860e@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
root@ess-os-7fda8fc:~#

When I added 

{
  "mtu": 1460
}

to /etc/docker/daemon.json
and restarted docker
`sudo systemctl restart docker`

I now have the mtu proper:

root@ess-os-7fda8fc:~# ip addr | grep mtu
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc mq state UP group default qlen 1000
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc noqueue state UP group default 
7: vethe49860e@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc noqueue master docker0 state UP group default 

And apt-get update in the docker now works!!!

Did the trick for me, thank you so much!!