Docker build(python image) 由于密码学问题失败
Docker build(python image) fails due to cryptography
我正在尝试为我的烧瓶服务器构建一个图像,我使用 pipreqs 生成了 requirements.txt。
requirements.txt 包含 cryptography==2.8
,每次尝试安装此版本时构建失败。不太清楚为什么,它甚至显示版本就在那里。
这是 docker 构建错误
22.90 ERROR: Could not find a version that satisfies the requirement cryptography==2.8
(from versions: 0.1, 0.2, 0.2.1, 0.2.2, 0.3, 0.4, 0.5, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.6, 0.6.1, 0.7, 0.7.1, 0.7.2, 0.8, 0.8.1, 0.8.2, 0.9, 0.9.1, 0.9.2, 0.9.3, 1.0, 1.0.1, 1.0.2, 1.1, 1.1.1, 1.1.2, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.4, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.6, 1.7, 1.7.1, 1.7.2, 1.8, 1.8.1, 1.8.2, 1.9, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.1, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.2, 2.2.1, 2.2.2, 2.3, 2.3.1, 2.4, 2.4.1, 2.4.2, 2.5, 2.6, 2.6.1, 2.7, 2.8, 2.9, 2.9.1, 2.9.2, 3.0, 3.1, 3.1.1, 3.2, 3.2.1, 3.3, 3.3.1, 3.3.2, 3.4, 3.4.1, 3.4.2, 3.4.3, 3.4.4, 3.4.5, 3.4.6, 3.4.7, 3.4.8, 35.0.0, 36.0.0, 36.0.1)
#8 22.90 ERROR: No matching distribution found for cryptography==2.8
#8 22.92 WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
#8 22.92 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
------
executor failed running [/bin/sh -c pip3 install -r requirements.txt]: exit code: 1
编辑:
即使不复制任何烧瓶代码,以下构建也会失败
FROM python:3.8.10-alpine3.13
RUN pip install cryptography==2.8
请查看并告诉我是否需要更多信息或哪里出错了。谢谢
我认为你的问题与 alpine linux 图像有关,我的意思是用于构建 python:3.9.10-alpine3.15 的基础图像你应该尝试按照提到的代码手动安装加密以下:
RUN apk add --no-cache \
libressl-dev \
musl-dev \
libffi-dev && \
pip install --no-cache-dir cryptography==2.8 && \
apk del \
libressl-dev \
musl-dev \
libffi-dev
Cryptography 文档还包含有关如何下载的信息
RUN apk add gcc musl-dev libffi-dev openssl-dev cargo
正如@Soheb 指出的那样,基本图像似乎有问题,它与 python:3.8.10-slim-buster
完美配合。不太确定以前的基本图像有什么问题
问题是 alpine
图像没有安装 gcc
,正如您在完整的错误消息中看到的那样(未在您的问题中显示,但可以通过 docker 轻松复制):
Unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
通过安装 gcc 和 cryptography
的依赖项修复它:
FROM python:3.8.10-alpine3.13
RUN apk add --no-cache \
build-base \
libressl-dev \
musl-dev \
libffi-dev
RUN pip install cryptography==2.8
您可能仍然想知道为什么会收到(令人困惑的)消息:
ERROR: Could not find a version that satisfies the requirement cryptography==2.8
(from versions: 0.1, 0.2, 0.2.1, 0.2.2, 0.3, 0.4, 0.5, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.6, 0.6.1, 0.7, 0.7.1, 0.7.2, 0.8, 0.8.1, 0.8.2, 0.9, 0.9.1, 0.9.2, 0.9.3, 1.0, 1.0.1, 1.0.2, 1.1, 1.1.1, 1.1.2, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.4, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.6, 1.7, 1.7.1, 1.7.2, 1.8, 1.8.1, 1.8.2, 1.9, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.1, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.2, 2.2.1, 2.2.2, 2.3, 2.3.1, 2.4, 2.4.1, 2.4.2, 2.5, 2.6, 2.6.1, 2.7, 2.8, 2.9, 2.9.1, 2.9.2, 3.0, 3.1, 3.1.1, 3.2, 3.2.1, 3.3, 3.3.1, 3.3.2, 3.4, 3.4.1, 3.4.2, 3.4.3, 3.4.4, 3.4.5, 3.4.6, 3.4.7, 3.4.8, 35.0.0, 36.0.0, 36.0.1)
错误消息只是陈述事实:pip
找不到
的版本
- 符合您的要求
- 可以正确安装
唯一满足1.(并已下载,查看完整安装日志)的版本不满足2.,因此被丢弃。然后会产生错误,其中包含 pip 根据条件 1. 和 2. 检查的所有版本的列表,即 pypi 上的所有版本,其中 OS 和 python 版本
的候选版本
我正在尝试为我的烧瓶服务器构建一个图像,我使用 pipreqs 生成了 requirements.txt。
requirements.txt 包含 cryptography==2.8
,每次尝试安装此版本时构建失败。不太清楚为什么,它甚至显示版本就在那里。
这是 docker 构建错误
22.90 ERROR: Could not find a version that satisfies the requirement cryptography==2.8
(from versions: 0.1, 0.2, 0.2.1, 0.2.2, 0.3, 0.4, 0.5, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.6, 0.6.1, 0.7, 0.7.1, 0.7.2, 0.8, 0.8.1, 0.8.2, 0.9, 0.9.1, 0.9.2, 0.9.3, 1.0, 1.0.1, 1.0.2, 1.1, 1.1.1, 1.1.2, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.4, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.6, 1.7, 1.7.1, 1.7.2, 1.8, 1.8.1, 1.8.2, 1.9, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.1, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.2, 2.2.1, 2.2.2, 2.3, 2.3.1, 2.4, 2.4.1, 2.4.2, 2.5, 2.6, 2.6.1, 2.7, 2.8, 2.9, 2.9.1, 2.9.2, 3.0, 3.1, 3.1.1, 3.2, 3.2.1, 3.3, 3.3.1, 3.3.2, 3.4, 3.4.1, 3.4.2, 3.4.3, 3.4.4, 3.4.5, 3.4.6, 3.4.7, 3.4.8, 35.0.0, 36.0.0, 36.0.1)
#8 22.90 ERROR: No matching distribution found for cryptography==2.8
#8 22.92 WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
#8 22.92 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
------
executor failed running [/bin/sh -c pip3 install -r requirements.txt]: exit code: 1
编辑: 即使不复制任何烧瓶代码,以下构建也会失败
FROM python:3.8.10-alpine3.13
RUN pip install cryptography==2.8
请查看并告诉我是否需要更多信息或哪里出错了。谢谢
我认为你的问题与 alpine linux 图像有关,我的意思是用于构建 python:3.9.10-alpine3.15 的基础图像你应该尝试按照提到的代码手动安装加密以下:
RUN apk add --no-cache \
libressl-dev \
musl-dev \
libffi-dev && \
pip install --no-cache-dir cryptography==2.8 && \
apk del \
libressl-dev \
musl-dev \
libffi-dev
Cryptography 文档还包含有关如何下载的信息
RUN apk add gcc musl-dev libffi-dev openssl-dev cargo
正如@Soheb 指出的那样,基本图像似乎有问题,它与 python:3.8.10-slim-buster
完美配合。不太确定以前的基本图像有什么问题
问题是 alpine
图像没有安装 gcc
,正如您在完整的错误消息中看到的那样(未在您的问题中显示,但可以通过 docker 轻松复制):
Unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
通过安装 gcc 和 cryptography
的依赖项修复它:
FROM python:3.8.10-alpine3.13
RUN apk add --no-cache \
build-base \
libressl-dev \
musl-dev \
libffi-dev
RUN pip install cryptography==2.8
您可能仍然想知道为什么会收到(令人困惑的)消息:
ERROR: Could not find a version that satisfies the requirement cryptography==2.8
(from versions: 0.1, 0.2, 0.2.1, 0.2.2, 0.3, 0.4, 0.5, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.6, 0.6.1, 0.7, 0.7.1, 0.7.2, 0.8, 0.8.1, 0.8.2, 0.9, 0.9.1, 0.9.2, 0.9.3, 1.0, 1.0.1, 1.0.2, 1.1, 1.1.1, 1.1.2, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.4, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.6, 1.7, 1.7.1, 1.7.2, 1.8, 1.8.1, 1.8.2, 1.9, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.1, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.2, 2.2.1, 2.2.2, 2.3, 2.3.1, 2.4, 2.4.1, 2.4.2, 2.5, 2.6, 2.6.1, 2.7, 2.8, 2.9, 2.9.1, 2.9.2, 3.0, 3.1, 3.1.1, 3.2, 3.2.1, 3.3, 3.3.1, 3.3.2, 3.4, 3.4.1, 3.4.2, 3.4.3, 3.4.4, 3.4.5, 3.4.6, 3.4.7, 3.4.8, 35.0.0, 36.0.0, 36.0.1)
错误消息只是陈述事实:pip
找不到
- 符合您的要求
- 可以正确安装
唯一满足1.(并已下载,查看完整安装日志)的版本不满足2.,因此被丢弃。然后会产生错误,其中包含 pip 根据条件 1. 和 2. 检查的所有版本的列表,即 pypi 上的所有版本,其中 OS 和 python 版本
的候选版本