在我的例子中,我们想要从一个要求*.txt 文件中安装 pip 模块,该文件中定义了 锁定 模块的版本并且仅从 内部 Artifactory 服务器解析(而不是在线,即 pypi.org)
例如:requirements.txt 文件
numpy==1.16.2
pandas==1.0.3
..
...
要解决此问题:我必须使用 NO_PROXY=<value> 作为环境变量。
假设您的工件服务器是:my-artifactory.company.local 或 my-artifactory.company.com,那么我们只需要确保NO_PROXY 变量的值中列出了该主机名的“domain”部分。
即为了
my-artifactory.company.com 或 my-artifactory.company.local,value inside
NO_PROXY 变量必须包含:,.company.com,.company.local,...。
示例导出的变量(在命令行 $ 提示符):
export NO_PROXY=localhost,127.0.0.1,169.254.169.254,169.254.169.123,.somecompany.com,.company.com,.company.local,pki.company.com,s3-us-gov-west-1.amazonaws.com,s3-fips-us-gov-west-1.amazonaws.com,rds.amazonaws.com,10.201.12.244,10.201.44.62,10.201.32.261
====
如果您使用的是Dockerfile,那么请确保您正确设置了 ARG/ENV 变量。
ARG 在构建时使用(可以在命令行中使用 --build-arg 发送到docker build -t tag . 的选项覆盖,它将在当前目录中搜索 Dockerfile 并创建映像。ENV 在运行时使用(docker run ) 并且也可以被覆盖。
示例 Dockerfile 是:
FROM python:3.7
MAINTAINER giga.sangal@company.com
ARG PYTHONBUFFERED=0
ARG HTTPS_PROXY=http://proxy.ext.company.com:80
ARG HTTP_PROXY=http://proxy.ext.company.com:80
ARG NO_PROXY=localhost,127.0.0.1,169.254.169.254,.company.com,.company.local,pki.company.com,s3-us-gov-west-1.amazonaws.com,s3-fips-us-gov-west-1.amazonaws.com,rds.amazonaws.com
ENV PYTHONBUFFERED=${PYTHONBUFFERED}
ENV HTTPS_PROXY=${HTTPS_PROXY}
ENV HTTP_PROXY=${HTTP_PROXY}
ENV NO_PROXY=${NO_PROXY}
# If there are 3 requirements files in source control, I'm copy all for pip install, you don't have to. Use what modules you want / file you want.
RUN mkdir -p code
COPY requirements.txt /code
COPY requirements-test.txt /code
COPY requirements-dev.txt /code
WORKDIR /code
# You can fetch from pypi.org but in my case, this was a security issue.
# RUN pip install --trusted-host pypi.org -r requirements.txt
RUN pip install --no-cache-dir --trusted-host my-artifactory.company.local -r requirements.txt -r requirements-test.txt -r requirements-dev.txt --index-url http://my-artifactory.company.local:8081/artifactory/api/pypi/pypi-local-deps/simple --disable-pip-version-check
在我的案例中解决问题的主线是使用 NO_PROXY(如上所列)。
任何与 pip 模块相关的问题,或未找到模块版本,或任何 SSL 错误SSLError(SSLCertVerificationError 类似错误,在 cmd 行 或 应用上述 NO_PROXY 后消失Dockerfile:
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)'))': /simple/requests/
或
ERROR: Could not find a version that satisfies the requirement requests
ERROR: No matching distribution found for requests
或
ERROR: Could not find a version that satisfies the requirement numpy==1.16.2
ERROR: No matching distribution found for numpy==1.16.2