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
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
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 comments
I 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:
root@6b0d832700db:/# ping google.com
ping: unknown host google.com
root@6b0d832700db:/# cat /etc/resolv.conf
search online.net
nameserver 8.8.8.8
nameserver 8.8.4.4
root@6b0d832700db:/# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=56 time=1.76 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=56 time=1.72 ms
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 adding local dns ip to default docker file it started working for me... please find the below steps...
$ nm-tool # (will give you the dns IP)
DNS : 172.168.7.2
$ vim /etc/default/docker # (uncomment the DOCKER_OPTS and add DNS IP)
DOCKER_OPTS="--dns 172.168.7.2 --dns 8.8.8.8 --dns 8.8.4.4"
$ rm `docker ps --no-trunc -aq` # (remove all the containers to avoid DNS cache)
$ docker rmi $(docker images -q) # (remove all the images)
$ service docker restart #(restart the docker to pick up dns setting)
Now go ahead and build the docker... :)
Before spending too much time on any of the other solutions, simply restart Docker and try again.
Solved the problem for me, using Docker Desktop for Windows on Windows 10.
I have struggled for some time with this now as well, but here it is what solved it for me on Ubuntu 16.04 x64
. I hope it saves someone's time, too.
In /etc/NetworkManager/NetworkManager.conf
:
comment out
#dns=dnsmasq
Create (or modify) /etc/docker/daemon.json
:
{
"dns": ["8.8.8.8"]
}
sudo service docker restart
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.
docker0 Link encap:Ethernet Endereço de HW 02:42:69:ba:b4:07
inet end.: 172.17.0.1 Bcast:0.0.0.0 Masc:255.255.0.0
endereço inet6: fe80::42:69ff:feba:b407/64 Escopo:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Métrica:1
pacotes RX:8433 erros:0 descartados:0 excesso:0 quadro:0
Pacotes TX:9876 erros:0 descartados:0 excesso:0 portadora:0
colisões:0 txqueuelen:0
RX bytes:484195 (484.1 KB) TX bytes:24564528 (24.5 MB)
It was 172.17.0.1
in my case. Hope this helps anyone who is also having this issue.