pip无法在Mac上的Docker容器内安装软件包 [英] pip unable to install packages inside docker container on mac

查看:254
本文介绍了pip无法在Mac上的Docker容器内安装软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循 Docker入门指南,将docker与python应用程序,但是当docker掌握以下命令时:

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

我收到以下错误消息:

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

pip似乎在容器外部工作正常.有什么办法可以允许它访问互联网?我已经为docker设置了代理,到目前为止,一切似乎都工作正常.

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).

所有相关问题都针对ubuntu或Windows,不适用于Mac.

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

提前谢谢.

推荐答案

我发现这是一个pip代理错误,并且能够通过将代理指定为pip安装的参数来解决此问题.因此,不仅仅是拥有

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

在我的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证书错误(在公司环境中很常见).

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).

这篇关于pip无法在Mac上的Docker容器内安装软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆