Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using pip in Docker container leads to ReadTimeoutError

Tags:

docker

pip

I try to install a package via pip. However, every usage of pip, which needs an Internet connection (even the upgrade below) leads to a ReadTimeoutError. My basic Dockerfile which is working on another system is as follows:

FROM python:3-alpine
RUN wget google.com
RUN pip3 -V
RUN pip3 install --upgrade pip

Line two shows shows that I have an Internet connection. Output:

Connecting to google.com (216.58.206.14:80)
Connecting to www.google.com (108.177.126.103:80)
index.html           100% |*******************************| 10582   0:00:00 ETA

Line three shows that pip is installed. Output:

pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)). 

However, line four leads to:

Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=100.0)",)': /simple/pip/

I already tried to:

  • reinstall Docker

  • increase the default timeout with "--default-timeout=100" (which is why the read timeout is 100 in above's error message.)

I read that there are problems with pip when you are behind a Proxy, which is not the case here. Do you have any other ideas what is wrong here?

Thanks in advance!

like image 593
Flo1895 Avatar asked Nov 17 '22 09:11

Flo1895


1 Answers

There are two possible solutions:

  1. This may not be a problem with network: I just found a solution in another place: Please add two lines after From layer
ENV http_proxy http://proxy-chain.xxx.com:911/
ENV https_proxy http://proxy-chain.xxx.com:912/ 

Or change to another mirror source: Add the following commands before pip install

RUN mkdir ~/.pip && \  
cd ~/.pip/  && \  
echo "[global] \ntrusted-host =  pypi.douban.com \nindex-url = http://pypi.douban.com/simple" >  pip.conf  
  1. If it is because of the network, cuz it takes time to connect the source maybe: Try to add the following limitation after pip install:
--default-timeout=1000 --no-cache-dir
like image 171
Newt Avatar answered Dec 06 '22 16:12

Newt