pip 无法在 Mac 上的 docker 容器内安装软件包

2024-02-21

我正在关注Docker-入门 https://docs.docker.com/get-started/part2/将 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

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

所有相关问题均针对 ubuntu 或 windows,不适用于 mac。

提前致谢。


我发现这是一个 pip 代理错误,并且能够通过将代理指定为 pip install 的参数来解决该问题。所以而不是简单地拥有

#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指定 pip 使用的代理--trusted-host pypi.python.org启用 pypi 作为受信任的主机,以防遇到 ssl 证书错误(在企业环境中常见)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

pip 无法在 Mac 上的 docker 容器内安装软件包 的相关文章

随机推荐