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 that was to install software it would fail with a message saying that the package was not found.
RUN apt-get -y install supervisor nodejs npm
The common message which showed up in the logs was
Could not resolve 'archive.ubuntu.com'
Any idea why any software will not install?
For anyone who is also having this problem, I solved my problem by editing the
/etc/default/docker
file, as suggested by other answers and questions. However I had no idea what IP to use as the DNS.It was only after a while I figured out I had to run
ifconfig docker
on the host to show the IP for the docker network interface.It was
172.17.0.1
in my case. Hope this helps anyone who is also having this issue.I have the same issue, and tried the steps mentioned, but seems none works until refresh the network settings.
The steps:
DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4 --ip-masq=true"
to/etc/default/docker
.iptables -t nat -F POSTROUTING
. After running this, restart docker and it will initialize the nat table with the new IP range.I got same issue today, I just added line below to /etc/default/docker
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.
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.
I just wanted to add a late response for anyone coming across this issue from search engines.
Do NOT do this: I used to have an option in /etc/default/docker to set
iptables=false
. This was because ufw didn't work (everything was opened even though only 3 ports were allowed) so I blindly followed the answer to this question: Uncomplicated Firewall (UFW) is not blocking anything when using Docker and this, which was linked in the commentsI have a very low understanding of iptables rules / nat / routing in general, hence why I might have done something irrational.
Turns out that I've probably misconfigured it and killed DNS resolution inside my containers. When I ran an interactive container terminal:
docker run -i -t ubuntu:14.04 /bin/bash
I had these results:
Reverting all of my ufw configuration (before.rules), disabling ufw and removing iptables=false from /etc/default/docker restored the DNS resolution functionality of the containers.
I'm now looking forward to re-enable ufw functionality by following these instructions instead.
After much headache I found the answer.
Could not resolve 'archive.ubuntu.com'
can be fixed by making the following changes:Uncomment the following line in
/etc/default/docker
DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
Restart the Docker service
sudo service docker restart
Delete any images which have cached the invalid DNS settings.
Credit goes to Andrew SB