Docker build “Could not resolve 'archive.ubunt

2019-01-07 02:07发布

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?

11条回答
聊天终结者
2楼-- · 2019-01-07 02:47

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.

查看更多
混吃等死
3楼-- · 2019-01-07 02:47

I have the same issue, and tried the steps mentioned, but seems none works until refresh the network settings.

The steps:

  1. As mentioned, add DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4 --ip-masq=true" to /etc/default/docker.
  2. Manually flush the PREROUTING table contents using the iptables -t nat -F POSTROUTING . After running this, restart docker and it will initialize the nat table with the new IP range.
查看更多
何必那么认真
4楼-- · 2019-01-07 02:47

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.

查看更多
Explosion°爆炸
5楼-- · 2019-01-07 02:50

Same issue for me (on Ubuntu Xenial).

  • docker run --dns ... for containers worked.
  • Updating docker daemon options for 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.

查看更多
够拽才男人
6楼-- · 2019-01-07 02:52

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.

查看更多
祖国的老花朵
7楼-- · 2019-01-07 02:53

After much headache I found the answer. Could not resolve 'archive.ubuntu.com' can be fixed by making the following changes:

  1. Uncomment the following line in /etc/default/docker
    DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"

  2. Restart the Docker service sudo service docker restart

  3. Delete any images which have cached the invalid DNS settings.

  4. Build again and the problem should be solved.

Credit goes to Andrew SB

查看更多
登录 后发表回答