Docker 名称解析暂时失败[ Errno-3]

我遵循的 码头教程和我的部分,我必须建立的应用程序使用:

docker build -t friendlyhello .

到了第4步,在暂停之后我得到了这个错误:

Step 4/7 : RUN pip install -r requirements.txt
---> Running in 7f4635a7510a
Collecting Flask (from -r requirements.txt (line 1))


Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after
connection broken by
'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection
object at 0x7fe3984d9b10>: Failed to establish a new connection:
[Errno -3] Temporary failure in name resolution',)': /simple/flask/

我不太确定这个错误意味着什么,也不知道如何去解决它。

谢谢你的帮助!

113775 次浏览

this post worked for me too!

Solved by dns mask [sic] disable:

sudo vim /etc/NetworkManager/NetworkManager.conf

comment out dns=dnsmasq -> #dns=dnsmasq

sudo service network-manager restart (or reboot VM in this case)

from: https://github.com/moby/moby/issues/26330

This error means your Docker container is unable to access your network. Beginning with systemd version 220, the forwarding setting for a given network (net.ipv4.conf..forwarding) defaults to off. This setting prevents IP forwarding. It also conflicts with Docker’s behavior of enabling the net.ipv4.conf.all.forwarding setting within containers.

If your container needs to resolve hosts which are internal to your network, the public nameservers will not be adequate. You have two choices:

  1. You can specify a DNS server for Docker to use, or
  2. You can disable dnsmasq in NetworkManager. If you do this, NetworkManager will add your true DNS nameserver to /etc/resolv.conf, but you will lose the possible benefits of dnsmasq. You only need to use one of these methods.

you can read about how to perform these steps here

I am having the same issue with Ubuntu 16.04.1 machine for docker-ce 17. Its got fixed by disable the dns mask in the network.

sudo nano /etc/NetworkManager/NetworkManager.conf

Press Ctrl+O save and Enter the exit Ctrl+X

Restart the network service by running bellow command.

sudo service network-manager restart

After this if you run the docker build command everything will work fine.

I got the same problem with Ubuntu 16.04 and Docker version 17.09.0-ce. I don't think disabling dnsmasq is the right solution.

Here is how I solved it:

For Ubuntu

Edit /etc/default/docker and add your DNS server to the following line:

Example

DOCKER_OPTS="--dns 8.8.8.8 --dns 10.252.252.252"

Reference: Network calls fail during image build on corporate network

It's silly, but I had a VPN connected when I got this error.

After disconnecting the VPN, PIP started working again.

bkasap's answer changes a system's feature I would say is exaggerated. Further because there are options in docker to do that. The new way to do that is

$ sudo vi /etc/docker/daemon.json

and add following content

{
"dns": ["8.8.8.8", "8.8.4.4"]
}

Don't forget to

sudo service docker restart

I just did sudo service docker restart and it worked after. Definitely worth a shot before jumping in to modify your configurations.

I had this problem on Windows 10 Pro and I solved it by right clicking on the docker icon in the tray and choosing "Restart...". It took a few mins and then the network was running fine again.

for me rebooting host machine resolved the issue

On fedora 32 it was problem with firewall. Following command resolved issue:

$firewall-cmd --permanent --zone=trusted --add-interface=docker0


$firewall-cmd --reload

Docker build: "Temporary failure in name resolution"

I also got the "temporary failure in name resolution" too. My solution was to specify the network on the docker build command:

s001# docker network create example_net
s001# docker build --network example_net -t example_image example_image
^^^^^^^^^^^^^^^^^^^

I also configured the dns on docker config on my development notebook:

s001# nano /etc/docker/daemon.json
{
"dns": ["8.8.8.8"]
}
s001# systemctl restart docker

Had this just now, on my Ubuntu 20.04. Randomly, it just stopped working!

Tried:

sudo service network-manager restart

Did not work. Then I just did:

sudo systemctl restart docker

and the issue was resolved!

My case was tricky and related to environmental conditions, but is worth mentioning. I was under a firewall with bandwidth limitations based on its own hierarchy-based logic (critical, hard, medium traffic, etc...).

Every time I was starting huge docker pull, everything on my host started misbehaving (https browser navigation based upon DNS, ping based upon DNS, ... and Docker, ofc.

Removing those limits fixed my problem, so check your network, too.

If you are facing it on windows machine,you can configure the way docker containers interact with network and set dns manually. Settings=>Resources=>Network=>Manual DNS Configuration Here is how it is configured

Don't forget to check your internet connection especially if you are using a virtual machine in cloud (for example EC2).

I had no internet connection when I tried to run a container in the EC2. I was connected by bastion host to the VM. I didn't have internet connection for the virtual machine.

I wasted too much time. I hope this answer helps the people like me.

I changed the default DNS server in /etc/resolv.conf and it worked for me.

FROM:

nameserver 127.0.0.53
options edns0 trust-ad

TO:

nameserver 8.8.8.8
#nameserver 127.0.0.53
options edns0 trust-ad


I just added the DNS server of Google and commented out the default DNS server.