I was facing internet issues when I was building docker images (especially installing npm/python packages from internet inside docker image), also, when docker container tried connecting to outside world(internet). Here is my experience on how I solved this.
I am using centos8 box with vagrant (2.2.9) and Oracle Virtual box(6.1.10) on Mac OS.
As the first step, I tried ping google.com from vagrant box, ping was successful and was able to connect to outside world. This gave me clear picture, docker was not able to connect to internet.
I was searching online, there were many sources, so, I was trying one by one.
The most recommended is enabling google dns in /etc/resolv.conf (of vagrant). But, unfortunately, this solution was not working.
Many recommended to use --dns, --dns-search option while running docker containers. But, I was facing issue while building docker images itself.
After searching a while, I ended up with working solution. Here is the reference.
It’s basically the issue with centos8 firewall, we need to add Masquerade to public zone, also adding docker0 interface to the public zone to access to internet. Here is the link to know more about firewalld.
https://www.linode.com/docs/security/firewalls/introduction-to-firewalld-on-centos/
Here are the commands I used –
Adding ‘docker0’ interface to ‘public’ zone
sudo nmcli connection modify docker0 connection.zone public
Masquerading allows for docker ingress
sudo firewall-cmd --zone=public --add-masquerade --permanent
To make the above changes to be effective, reload the firewall and also the docker
sudo firewall-cmd --reload
sudo service docker restart