2

I have been following the official Docs here.

My Dockerfile, app.py and requirements.txt are same as that given in the tutorial.
When I try to build my Docker image using docker build -t friendlyhello . I get the following error while docker runs the RUN pip install -r requirements.txt section:

Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/

I have already checked out this and tried all the proposed solutions none seem to work.

Thanks in advance.

Edit 1: My requirements.txt

Flask Redis

The complete output

Sending build context to Docker daemon 4.608 kB
Step 1/7 : FROM python:2.7-slim
---> 4ba53c70eb04
Step 2/7 : WORKDIR /app
---> Using cache
---> bebf675fc3bd
Step 3/7 : ADD . /app
---> Using cache
---> 435299812b68
Step 4/7 : RUN pip install -r requirements.txt
---> Running in 97465239272f
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 0x7f29c8b33910>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f29c8bb9f90>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/
Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f29c9aa69d0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/
Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f29c9aa6190>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f29c9aa6510>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/
Could not find a version that satisfies the requirement Flask (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for Flask (from -r requirements.txt (line 1))
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

Edit 2: I found out my company uses a specific DNS using which I could resolve docker run --dns [DNS] busybox nslookup google.com

Vivek Shankar
  • 770
  • 1
  • 15
  • 37

2 Answers2

1

If you need to update your daemon to use a different DNS address, you can create (or modify) the /etc/docker/daemon.json file with the following:

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

Just replace the above IP's with your own requirements and when finished, you can run a reload or restart on your daemon to reread the file.

sudo systemctl reload docker

This should change the default DNS for all new containers including those used when building.

See the following link for more details on what you can set in this file: https://docs.docker.com/engine/reference/commandline/dockerd/#linux-configuration-file

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • I carried out your instructions but `nslookup` couldn't resolve google.com even after I updated the `daemon.json` file. However if I manually add the dns with `--dns ` it works. – Vivek Shankar Jun 16 '17 at 07:14
1

The issue is in resolving the DNS in the containers. To resolve that follow the procedure which help to resolve the DNS in docker containers:

Find out the DNS server used in your machine :

# nm-tool  |grep DNS
    DNS:             172.24.100.50
    DNS:             10.1.100.50

Run it again using DNS IP found in the above step which resolves the DNS issue:

# docker run --dns 172.24.100.50 busybox nslookup google.com
Server:    172.24.100.50
Address 1: 172.24.100.50 indc01.radisys.com
Name:      google.com
Address 1: 2607:f8b0:4009:80c::200e ord36s01-in-x0e.1e100.net
Address 2: 172.217.4.110 ord36s04-in-f14.1e100.net

To resolve it permanently add the following content as below to a new file:

# cat /etc/docker/daemon.json
{
    "dns" : ["172.24.100.50", "8.8.8.8"]
}

More info on Docker DNS configuration : https://docs.docker.com/engine/userguide/networking/configure-dns/

Restart the docker service and check it again:

# docker run busybox nslookup google.com
Server:    172.24.100.50
Address 1: 172.24.100.50 indc01.radisys.com
Name:      google.com
Address 1: 2607:f8b0:4009:801::200e ord30s31-in-x0e.1e100.net
Address 2: 172.217.4.238 ord30s31-in-f14.1e100.net

Check it by running the container:

root@labadmin-VirtualBox:/home/labadmin# docker run -it e02e811dd08f
/ # ping google.com
PING google.com (172.217.4.238): 56 data bytes
64 bytes from 172.217.4.238: seq=0 ttl=47 time=251.506 ms
64 bytes from 172.217.4.238: seq=1 ttl=47 time=245.621 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 245.621/257.113/272.586 ms
/ #
Here_2_learn
  • 5,013
  • 15
  • 50
  • 68