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

后端 未结 15 2126
日久生厌
日久生厌 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: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.

提交回复
热议问题