91

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!

davidism
  • 121,510
  • 29
  • 395
  • 339
monadoboi
  • 1,651
  • 3
  • 16
  • 26
  • 5
    The error means pip had failed to resolve DNS name. First, check if networking works in Docker. Run `docker -it --rm python:2.7-slim /bin/bash` and then try running `ping pypi.python.org` and `ping -n 8.8.8.8`. Exit with ctrl-D or `exit`. If ping fails (post the results), then you have a problem with networking or DNS (update your question with OS details and Docker version). If it works, then, well, I suppose, you've ran into some bug with either Docker or pip - try adding `--verbose` so the command will be `RUN pip install --verbose -r requirements.txt`, maybe it'll provide something useful. – drdaeman Jun 26 '17 at 14:11
  • Thanks for your reply. The ping did indeed work fine, however the first command you mentioned, just gave me the error: unknown shorthand for i in '-it'. When running with `--verbose` I get the following: `Getting page https://pypi.python.org/simple/flask/ Looking up "https://pypi.python.org/simple/flask/" in the cache No cache entry available` – monadoboi Jun 26 '17 at 14:27
  • 6
    The first command @drdaeman mentioned fails because it lacks the run command. Use this instead: `docker run -it --rm python:2.7-slim /bin/bash` – yago Mar 17 '18 at 12:38
  • 2
    Did you suspend your computer in the before building the container? On my laptop, docker deamon always stops name resolution after suspending. When I wake up the laptop again I always need to restart the deamon to get it back to work. – Peter Jul 01 '19 at 08:54
  • 2
    Does this answer your question? [Network calls fail during image build on corporate network](https://stackoverflow.com/questions/24151129/network-calls-fail-during-image-build-on-corporate-network) – Ian Kemp Apr 09 '21 at 14:08

18 Answers18

87

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

David Warnke
  • 1,078
  • 8
  • 7
  • 12
    Need to do this every time I suspended/woke up my laptop, to get dns resolution inside docker back to work. – Peter Jul 01 '19 at 08:56
  • 1
    A good advice indeed. Before fiddling with config, try the basics. Also going inside the container with an interactive session is always a nice way to understand what's wrong _before_ applying a solution. `docker run -it --entrypoint /bin/sh name-of-your-image-here` – Bruno Bossola Apr 01 '20 at 11:18
35

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

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Jack Fan
  • 2,143
  • 3
  • 18
  • 25
29

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
JAR
  • 408
  • 4
  • 5
22

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

After disconnecting the VPN, PIP started working again.

James Anderson
  • 420
  • 5
  • 13
17

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

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

$firewall-cmd --reload
Robert Bielicki
  • 170
  • 1
  • 5
16

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

sehe
  • 374,641
  • 47
  • 450
  • 633
bkasap
  • 161
  • 4
  • 3
    Why is everybody willingly calling masquerading masking (not just this answer)? The difference matters - especially for understanding. We don't want to just mash keys until "it works". We need to understand what works, and why. (I realize this was a quote, but just search this SO post for `mask` to see my point) – sehe Dec 18 '18 at 13:35
12

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!

babis21
  • 1,515
  • 1
  • 16
  • 29
8

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

Abhishek Jha
  • 935
  • 2
  • 10
  • 22
5

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.

Abhilash KK
  • 448
  • 5
  • 19
2

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.

Ryan Shillington
  • 23,006
  • 14
  • 93
  • 108
2

for me rebooting host machine resolved the issue

voy
  • 1,568
  • 2
  • 17
  • 28
2

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
Lucas
  • 258
  • 2
  • 5
1

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.

Hayk
  • 187
  • 1
  • 10
0

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.

Patrizio Bertoni
  • 2,582
  • 31
  • 43
0

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

erhan355
  • 806
  • 11
  • 23
0

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.

emert117
  • 1,268
  • 2
  • 20
  • 38
0

Thats the solution that worked for me:

https://forums.docker.com/t/docker-build-fails-on-pip-install-from-temporary-failure-in-name-resolution/87227

Just executed docker network list and tested with the differents networks on the docker build --network=XXX .. The one that worked was host.

0

I was using "Cisco AnyConnect" as a VPN client on Ubuntu. It was disconnecting every time a URL had to be resolved.

I ended up using another VPN client.

Daan
  • 7,685
  • 5
  • 43
  • 52