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

PythonUbuntuDockerPipUbuntu 16.04

Python Problem Overview


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

docker build -t friendlyhello .

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

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!

Python Solutions


Solution 1 - Python

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

Solution 2 - Python

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: https://stackoverflow.com/questions/24151129/docker-network-calls-fail-during-image-build-on-corporate-network

Solution 3 - Python

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

Solution 4 - Python

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

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

$firewall-cmd --reload

Solution 5 - Python

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

Solution 6 - Python

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

After disconnecting the VPN, PIP started working again.

Solution 7 - Python

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!

Solution 8 - Python

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

Solution 9 - Python

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.

Solution 10 - Python

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.

Solution 11 - Python

for me rebooting host machine resolved the issue

Solution 12 - Python

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

Solution 13 - Python

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.

Solution 14 - Python

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.

Solution 15 - Python

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

Solution 16 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmonadoboiView Question on Stackoverflow
Solution 1 - PythonDavid WarnkeView Answer on Stackoverflow
Solution 2 - PythonJack FanView Answer on Stackoverflow
Solution 3 - PythonJARView Answer on Stackoverflow
Solution 4 - PythonRobert BielickiView Answer on Stackoverflow
Solution 5 - PythonbkasapView Answer on Stackoverflow
Solution 6 - PythonJames AndersonView Answer on Stackoverflow
Solution 7 - Pythonbabis21View Answer on Stackoverflow
Solution 8 - PythonAbhishek JhaView Answer on Stackoverflow
Solution 9 - PythonAbhilash KKView Answer on Stackoverflow
Solution 10 - PythonRyan ShillingtonView Answer on Stackoverflow
Solution 11 - PythonvoyView Answer on Stackoverflow
Solution 12 - PythonLucasView Answer on Stackoverflow
Solution 13 - PythonHaykView Answer on Stackoverflow
Solution 14 - PythonPatrizio BertoniView Answer on Stackoverflow
Solution 15 - Pythonerhan355View Answer on Stackoverflow
Solution 16 - Pythonemert117View Answer on Stackoverflow