IT박스

Docker 빌드“ 'archive.ubuntu.com'을 해결할 수 없습니다.”apt-get이 아무것도 설치하지 못함

itboxs 2020. 8. 31. 07:34
반응형

Docker 빌드“ 'archive.ubuntu.com'을 해결할 수 없습니다.”apt-get이 아무것도 설치하지 못함


이전에 작동했던 다양한 파일에서 Docker 빌드를 실행하려고 시도했지만 이제는 더 이상 작동하지 않습니다.

Docker 파일에 소프트웨어를 설치할 줄이 포함 되 자마자 패키지를 찾을 수 없다는 메시지와 함께 실패합니다.

RUN apt-get -y install supervisor nodejs npm

로그에 나타난 일반적인 메시지는

Could not resolve 'archive.ubuntu.com'

소프트웨어가 설치되지 않는 이유를 아십니까?


의 주석 DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"/etc/default/docker매트 캐리어가 제안하는 것은 않았다 NOT 나를 위해 작동합니다. 또한 회사의 DNS 서버를 해당 파일에 넣지 않았습니다. 그러나 다른 방법이 있습니다 (계속 읽으십시오).

먼저 문제를 확인하겠습니다.

$ docker run --rm busybox nslookup google.com   # takes a long time
nslookup: can't resolve 'google.com'   # <--- appears after a long time
Server:    8.8.8.8
Address 1: 8.8.8.8

명령이 중단 된 것처럼 보이지만 결국 " 'google.com'을 해결할 수 없습니다."라는 오류가 나오면 저와 같은 문제가있는 것입니다.

nslookup명령은 'google.com'의 텍스트 주소를 IP 주소로 바꾸기 위해 DNS 서버 8.8.8.8을 쿼리합니다. 아이러니하게도 8.8.8.8은 Google의 공개 DNS 서버 입니다. 경우 nslookup실패 8.8.8.8 같은 공공 DNS 서버는 귀하의 회사에 의해 차단 될 수 있습니다 (I 보안상의 이유로 가정).

당신은 당신의 회사의 DNS 서버를 추가하는 것을 생각할 것 DOCKER_OPTS에서하는 /etc/default/docker트릭을 할해야하지만, 어떤 이유, 그것은 나를 위해 일을하지 않았다. 나는 아래에서 나를 위해 일한 것을 설명합니다.

해결책 :

호스트 (Ubuntu 16.04를 사용하고 있음)에서 기본 및 보조 DNS 서버 주소를 찾습니다.

$ nmcli dev show | grep 'IP4.DNS'
IP4.DNS[1]:              10.0.0.2
IP4.DNS[2]:              10.0.0.3

이 주소를 사용하여 파일을 만듭니다 /etc/docker/daemon.json.

$ sudo su root
# cd /etc/docker
# touch daemon.json

이것을 넣으십시오 /etc/docker/daemon.json:

{                                                                          
    "dns": ["10.0.0.2", "10.0.0.3"]                                                                           
}     

루트에서 종료 :

# exit

이제 docker를 다시 시작하십시오.

$ sudo service docker restart

확인 :

이제 /etc/docker/daemon.json파일 을 추가하면 'google.com'을 IP 주소로 확인할 수 있는지 확인합니다 .

$ docker run --rm busybox nslookup google.com
Server:    10.0.0.2
Address 1: 10.0.0.2
Name:      google.com
Address 1: 2a00:1450:4009:811::200e lhr26s02-in-x200e.1e100.net
Address 2: 216.58.198.174 lhr25s10-in-f14.1e100.net

참조 :

저는 솔루션에 대한 모든 공로를 인정받을 자격이있는 Robin Winslow의 기사를 기반으로 솔루션을 기반으로했습니다. 고마워, 로빈!

"Docker의 네트워킹 DNS 구성 수정." 로빈 윈 슬로우. 2016 년 11 월 9 일에 확인 함. https://robinwinslow.uk/2016/06/23/fix-docker-networking-dns/


많은 두통 끝에 나는 답을 찾았습니다. Could not resolve 'archive.ubuntu.com'다음과 같이 변경하여 수정할 수 있습니다.

  1. 다음 줄의 주석 처리를 제거하십시오. /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


I run into the same problem, but neiter uncommenting /etc/default/docker dns entries nor editing the /etc/resolv.conf in the build container or the /etc/docker/daemon.json helps for me.

But after I build with the option --network=host the resolving was fine again.

docker build --network=host -t my-own-ubuntu-like-image .

Maybe this will help someone again.


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.


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... :)


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.


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.


I found this answer after some Googleing. I'm using Windows, so some of the above answers did not apply to my file system.

Basically run:

docker-machine ssh default
echo "nameserver 8.8.8.8" > /etc/resolv.conf

Which just overwrites the existing nameserver used with 8.8.8.8 I believe. It worked for me!


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.

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.


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.


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.


On my system (macOS High Sierra 10.13.6 with Docker 2.1.0.1) this was due to a corporate proxy.

I solved this by two steps:

  1. Manually configure proxy settings in Preferences>Proxies
  2. Add the same settings to your config.json inside ~/.docker/config.json like:

     "proxies":
    {
      "default":
      {
        "httpProxy": "MYPROXY",
        "httpsProxy": "MYPROXY",
        "noProxy": "MYPROXYWHITELIST"
      }
    }
    

참고URL : https://stackoverflow.com/questions/24991136/docker-build-could-not-resolve-archive-ubuntu-com-apt-get-fails-to-install-a

반응형