So, simple:
- Create a new VM in GCe, choose ubuntu 20.04, and enable the ip_forwarding.
- SSH into it, and install docker. Following the official ubuntu installation guide https://docs.docker.com/engine/install/ubuntu
- 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
- 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
- Restart the machine
- Run a simple image with network tools `docker run -it praqma/network-multitool bash`
- run `curl https://yahoo.com`
- run `ping yahoo.com`
- run `apk update`
- 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.