Docker populates /etc/resolv.conf by copying the /etc/resolv.conf host and filtering out all local name servers, such as 127.0.1.1. If there are no name servers left after that, Docker will add Googleโs public DNS servers (8.8.8.8 and 8.8.4.4).
According to the Docker documentation :
Note If you need access to the localhost host identifier, you must change the DNS service on the host to listen for a non-local address accessible from the container.
The host DNS service is dnsmasq, so if you force dnsmasq to listen on your docker IP address and add it to resolv.conf, docker will configure the containers to use this as a name server.
1 Create / edit /etc/dnsmasq.conf โ and add the following lines:
interface=lo interface=docker0
2 Find your docker IP address (in this case 172.17.0.1 ):
root@host :~
3 Create / edit /etc/resolvconf/resolv.conf.d/tail and add /etc/resolvconf/resolv.conf.d/tail line:
nameserver 172.17.0.1
4 Restart the network, update resolv.conf , restart the docker:
sudo service network-manager restart sudo resolvconf -u sudo service docker restart
Now your containers will be able to resolve DNS from any DNS servers that the host uses.
โ The path may be /etc/dnsmasq.conf , /etc/dnsmasq.conf.d/docker.conf , /etc/NetworkManager/dnsmasq.conf or /etc/NetworkManager/dnsmasq.d/docker.conf depending on your system and personal preferences.
source share