0

I am following the Docker-getting started guide to using docker with a python application, but when docker gets up to the command:

RUN pip install -r requirements.txt

I'm getting the following error message:

Step 4/7 : RUN pip install -r requirements.txt
---> Running in 98e18cf80a64
Collecting Flask (from -r requirements.txt (line 1))
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) 
after connection broken by 'NewConnectionError
('<pip._vendor.requests.packages.urllib3.connection.Ver
ifiedHTTPSConnection object at 0x7fb43609ccd0>: Failed to establish a 
new connection: [Errno 111] Connection refused',)': /simple/flask/

which repeats several times and then this appears:

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

pip seems to be working fine outside of the container. Is there any way i could allow it internet access? I have already set the proxy for docker and everything seems to be working fine except this (so far).

All the related questions address ubuntu or windows and are not usable for mac.

Thanks in advance.

Anthony Okoth
  • 448
  • 11
  • 32

2 Answers2

3

I have found out that this is a pip proxy error and was able to solve the issue by specifying the proxy as a parameter to pip install. So instead of simply having

#Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

in my Dockerfile, i had

#Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt --proxy http(s)://proxy:8080 --trusted-host pypi.python.org

The --proxy http(s)://proxy:8080 specifies the proxy to be used by pip and --trusted-host pypi.python.org enables pypi as a trusted host just in case ssl certificate errors are encountered (common in corporate environments).

phd
  • 82,685
  • 13
  • 120
  • 165
Anthony Okoth
  • 448
  • 11
  • 32
0

The only solution that worked for me was to include in my Dockerfile this line:

RUN pip install <package name> -i <package URL>

instead of having it in my requirements.txt.

When it was in requirements.txt I think Docker wasn't looking at package URL.

Spencer Goff
  • 1,036
  • 3
  • 14
  • 23