I\'ve been trying to run Docker build on various files which previously worked before, which are now no longer working.
As soon as the Docker file included any line
I got same issue today, I just added line below to /etc/default/docker
DOCKER_OPTS="--dns 172.18.20.13 --dns 172.20.100.29 --dns 8.8.8.8"
and then I restarted my Laptop.
In my case restarting docker daemon is not enough for me, I have to restart my Laptop to make it work.
I believe that Matt Carrier's answer is the correct solution for this problem. However, after implementing it, I still observed the same behavior: could not resolve 'archive.ubuntu.com'
.
This led me to eventually find that the network I was connected to was blocking public DNS. The solution to this problem was to configure my Docker container to use the same name server that my host (the machine from which I was running Docker) was using.
How I triaged:
docker run -it docker/whalesay bash
ping 172.217.4.238
(google.com)ping google.com
In my case, the first ping
resulted in responses, the second did not.
How I fixed:
Once I discovered that DNS was not working inside the container, I verified that I could duplicate the same behavior on the host. nslookup google.com
resolved just fine on the host. But, nslookup google.com 8.8.8.8
or nsloookup google.com 8.8.4.4
timed out.
Next, I found the name server(s) that my host was using by running nm-tool
(on Ubuntu 14.04). In the vein of fast feedback, I started up the example image again, and added the IP address of the name server to the container's resolv.conf file: sudo vi /etc/resolv.conf
. Once saved, I attempted the ping again (ping google.com
) and this time it worked!
Please note that the changes made to the container's resolv.conf are not persistent and will be lost across container restarts. In my case, the more appropriate solution was to add the IP address of my network's name server to the host's /etc/default/docker
file.
Same issue for me (on Ubuntu Xenial).
docker run --dns ...
for containers worked. docker build
(docker-compose etc.) did not work.After analyzing the docker logs (journalctl -u docker.service
) if found some warning about bad resolvconf applied.
Following that i found that our corporate nameservers were added to the network interfaces but not in resolvconf.
Applied this solution How do I configure my static DNS in interfaces? (askubuntu), i.e. adding nameservers to /etc/resolvconf/resolv.conf.d/tail
After updating resolvconf (or reboot).
bash
docker run --rm busybox nslookup google.com
worked instantly.
All my docker-compose builds are working now.