簡體   English   中英

pip無法在Mac上的Docker容器內安裝軟件包

[英]pip unable to install packages inside docker container on mac

我正在遵循Docker入門指南,將docker與python應用程序結合使用,但是當docker掌握以下命令時:

RUN pip install -r requirements.txt

我收到以下錯誤消息:

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/

重復幾次,然后出現:

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

點子似乎在容器外部工作正常。 有什么辦法可以允許它訪問互聯網? 我已經為docker設置了代理,除了到目前為止(到目前為止),一切似乎都工作正常。

所有相關問題都針對ubuntu或Windows,不適用於Mac。

提前致謝。

我發現這是一個pip代理錯誤,並且可以通過將代理指定為pip安裝的參數來解決此問題。 因此,與其簡單地擁有

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

在我的Dockerfile

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

--proxy http(s)://proxy:8080指定pip使用的代理,而--trusted-host pypi.python.org pypi設為受信任的主機,以防萬一遇到ssl證書錯誤(常見於公司環境)。

對我有用的唯一解決方案是在我的Dockerfile中包含以下行:

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

而不是放在我的requirements.txt中。

當它位於requirements.txt中時,我認為Docker不在查看包URL。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM