Search code examples
pythondockerpipubuntu-16.04

pip install not working inside docker container


I have created a small project in flask and I am trying to deploy it using docker. For this I have created my Dockerfile that looks like following:

FROM python:3.6-stretch

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app 
ADD . /app

# Install the dependencies
RUN pip install --user -r requirements.txt

# run the command to start uWSGI
CMD ["uwsgi", "app.ini"]

My requirements.txt file contains the following:

#click==7.1.1
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
uWSGI==2.0.18
Werkzeug==1.0.1

I tried to build my project using docker-build with --network=host option and also usingdocker-compose, but have not been successful. I get the following error:

    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fac273160f0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/flask/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fac27316588>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/flask/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fac27316828>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/flask/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fac273166a0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/flask/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fac273168d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/flask/
ERROR: Could not find a version that satisfies the requirement Flask==1.1.2 (from -r requirements.txt (line 2)) (from versions: none)
ERROR: No matching distribution found for Flask==1.1.2 (from -r requirements.txt (line 2))

I have no clue why I am getting this error. Can somebody help me with this? I am running docker-compose build command inside python virtual environment.


Solution

  • I have solved this problem. I had to create a file /etc/docker/daemon.json and add the following section:

    {
      "dns": ["myDNS"]
    }
    

    The value of myDNS was obtained using the following:

    nmcli dev show | grep 'DNS'
    

    After that I restarted my docker and was able to install the dependencies.