Docker build “Could not resolve 'archive.ubuntu.com'” apt-get fails to install anything

后端 未结 15 2117
日久生厌
日久生厌 2020-11-28 17:45

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

相关标签:
15条回答
  • 2020-11-28 18:32

    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.

    0 讨论(0)
  • 2020-11-28 18:34

    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:

    1. Since I was working through the Docker documentation, I already had an example image installed on my machine. I was able to start a new container to run that image and create a new bash session in that container: docker run -it docker/whalesay bash
    2. Does the container have an Internet connection?: ping 172.217.4.238 (google.com)
    3. Can the container resolve hostnames? 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.

    0 讨论(0)
  • 2020-11-28 18:35

    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.

    0 讨论(0)
提交回复
热议问题