python - pip无法在Mac上的Docker容器内安装软件包

标签 python macos docker pip

我正在按照Docker-getting started指南将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证书错误(在公司环境中常见)。

关于python - pip无法在Mac上的Docker容器内安装软件包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45082080/

相关文章:

python - 在python3中创建变量来分配多个值

swift - 如何在 Process() 中包含命令修饰符?

node.js - 请在 docker npm test 中设置 "CHROME_BIN"env 变量

azure - 如何在已部署的 Azure Docker Windows 容器实例中执行命令

python : optional arguments for function calling lower level functions

Python Selenium Webdriver - 即时更改代理设置

python - 如何将向量分离为基向量?

objective-c - 有没有办法以编程方式在 OSX 上静音?

windows - 如何创建容器文件?

docker - 即使根文件系统不存在,如何删除 docker 容器?