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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44761246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:25:33  来源:igfitidea点击:

Temporary failure in name resolution [Errno -3] with Docker

pythonubuntudockerpipubuntu-16.04

提问by monadoboi

I'm following the docker tutorialand am on the part where I have to build the app using:

我正在关注docker 教程,并且我必须使用以下方法构建应用程序:

docker build -t friendlyhello .

It reaches up to step 4, where after a pause I get this error:

它到达第 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/

I'm not quite sure what this error means and how I can go about solving it.

我不太确定这个错误意味着什么以及我如何解决它。

Thanks for your help!

谢谢你的帮助!

回答by Hyman Fan

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

我在 Ubuntu 16.04 和 Docker 版本 17.09.0-ce 上遇到了同样的问题。我不认为禁用 dns 掩码是正确的解决方案。

Here is how I solved it:

这是我解决它的方法:

For Ubuntu

对于 Ubuntu

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

编辑 /etc/default/docker 并将您的 DNS 服务器添加到以下行:

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

例子 DOCKER_OPTS="--dns 8.8.8.8 --dns 10.252.252.252"

Reference: Docker - Network calls fail during image build on corporate network

参考: Docker - 在企业网络上构建映像期间网络调用失败

回答by bkasap

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)

通过 dns mask [sic]disable 解决:

须藤vim /etc/NetworkManager/NetworkManager.conf

注释掉 dns=dnsmasq -> #dns=dnsmasq

sudo service network-manager restart (或在这种情况下重新启动 VM)

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

来自:https: //github.com/moby/moby/issues/26330

回答by David Warnke

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

我刚做了sudo service docker restart,之后就起作用了。在开始修改配置之前绝对值得一试。

回答by JAR

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

bkasap 的回答改变了一个系统的功能,我会说它被夸大了。此外,因为 docker 中有选项可以做到这一点。这样做的新方法是

$ 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

回答by James Anderson

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

这很愚蠢,但是当我收到此错误时,我连接了 VPN。

After disconnecting the VPN, PIP started working again.

断开 VPN 连接后,PIP 再次开始工作。

回答by Abhilash

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.

我在 docker-ce 17 的 Ubuntu 16.04.1 机器上遇到了同样的问题。它通过禁用网络中的 dns 掩码得到了修复。

sudo nano /etc/NetworkManager/NetworkManager.conf 

Press Ctrl+Osave and Enterthe exit Ctrl+X

Ctrl+O保存并输入退出Ctrl+X

Restart the network service by running bellow command.

通过运行 bellow 命令重新启动网络服务。

sudo service network-manager restart

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

在此之后,如果您运行 docker build 命令,一切都会正常进行。

回答by Abhishek Jha

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.

此错误意味着您的 Docker 容器无法访问您的网络。从 systemd 版本 220 开始,给定网络 (net.ipv4.conf..forwarding) 的转发设置默认为关闭。此设置可防止 IP 转发。它还与 Docker 在容器内启用 net.ipv4.conf.all.forwarding 设置的行为相冲突。

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.
  1. 您可以指定一个 DNS 服务器供 Docker 使用,或者
  2. 您可以在 NetworkManager 中禁用 dnsmasq。如果您这样做,NetworkManager 会将您真正的 DNS 名称服务器添加到 /etc/resolv.conf,但您将失去 dnsmasq 可能带来的好处。您只需要使用这些方法之一。

you can read about how to perform these steps here

您可以在此处阅读有关如何执行这些步骤的信息

回答by Ryan Shillington

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.

我在 Windows 10 Pro 上遇到了这个问题,我通过右键单击托盘中的泊坞窗图标并选择“重新启动...”来解决它。花了几分钟,然后网络再次运行良好。

回答by voy

for me rebooting host machine resolved the issue

对我来说,重新启动主机解决了这个问题

回答by Robert Bielicki

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

在 Fedora 32 上,防火墙有问题。以下命令解决了问题:

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

$firewall-cmd --reload