4

I am following the tutorial in https://docker-curriculum.com/ to produce my first Docker image. In section 2.4 we are taught how to configure a simple Dockerfile using the base image python:3-onbuild that will automatically run pip and install dependencies from the requirements.txt.

The problem is the when I try to build docker, the packages simply fail to load:

mgitt@mgpc:~/workspace/docker-curriculum/flask-app$ docker build -t prakhar1989/catnip .
Sending build context to Docker daemon  8.704kB
Step 1/3 : FROM python:3-onbuild
# Executing 3 build triggers...
Step 1/1 : COPY requirements.txt /usr/src/app/
 ---> Using cache
Step 1/1 : RUN pip install --no-cache-dir -r requirements.txt
 ---> Running in 74c4e94fa1ba
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 0x7fc6592831d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /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 0x7fc659283cc0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /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 0x7fc659283208>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /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 0x7fc659283470>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /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 0x7fc659283ba8>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /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 --no-cache-dir -r requirements.txt' returned a non-zero code: 1
mgitt@mgpc:~/workspace/docker-curriculum/flask-app$ 

I have taken a look at this stackoverflow solution. These answers seem to have fixed many peoples problem issue of not being able to connect with the Domain Name Server (DNS) but resetting docker or adding the DNS to /etc/dhcp/dhclient.conf did nothing for me.

I have Docker version 17.09.0-ce installed and am running on Ubuntu 16.04, any ideas?

Max
  • 2,072
  • 5
  • 26
  • 42
  • @JanezKuhar This doesn't seem to be the issue, as I am pulling a `User image`, it is like cloning someones repository. I also tried your solution, this led to the same result – Max Oct 11 '17 at 17:59
  • The error message says there's a connection error when trying to reach to https://pypi.python.org/pypi. Can the machine you're building the image on connect to that site? – jwodder Oct 11 '17 at 18:23
  • No I cannot. Essentially the problem is that I cannot connect to the server because my machine can't find the correct DNS. But after trying the solutions in the SO solution, I am still unable to connect – Max Oct 11 '17 at 18:45
  • Are you running behind a proxy? – yamenk Oct 11 '17 at 19:09
  • In firefox I managed to find `Use system proxy settings` enabled. I supposed this means my entire system uses a proxy – Max Oct 11 '17 at 19:34
  • This has been the most helpful link yet https://docs.docker.com/engine/userguide/networking/configure-dns/ – Max Oct 11 '17 at 19:37
  • I tried the above on a different computer, on a different network. Ubuntu 16.04 and it had no problems downloading Flask, so @yamenk you are on to something – Max Oct 11 '17 at 20:11

1 Answers1

3

If you are working on a proxy. There is a strong probability that docker containers cannot reach the internet at all.

You can test this by running

$ docker run -it busybox sh
/ # ping google.com

If it hangs you know you have a problem. Now we must find the network interface that your host machine uses to connect to the internet. ipconfig will give you a list of names, whichever one is used to connect to the internet is your IFACENAME. Now run:

$ nmcli dev list | grep 'IP4.DNS'                    # Ubuntu <= 14
$ nmcli device show IFACENAME | grep IP4.DNS         # Ubuntu >= 15

This will list out the IP_ADDRESS that your proxy server is located on. There may be more than 1, just use the first one. Create the file /etc/docker/daemon.json with the following contents:

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

Lastly,

$ sudo service docker restart

You should now be able to ping from within a container.

Max
  • 2,072
  • 5
  • 26
  • 42