简体   繁体   English

Docker 构建(python 图像)由于密码学而失败

[英]Docker build(python image) fails due to cryptography

I am trying to build an image for my flask server, I generated the requirements.txt using pipreqs.我正在尝试为我的 flask 服务器构建映像,我使用 pipreqs 生成了 requirements.txt。

The requirements.txt contains cryptography==2.8 and everytime the build fails on while trying to install this version. requirements.txt 包含cryptography==2.8并且每次在尝试安装此版本时构建失败。 Not too sure why, it even shows that the version is right there.不太清楚为什么,它甚至表明版本就在那里。

Here is the docker build error这是 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

EDIT: Even without copying any of the flask code, the following build fails编辑:即使没有复制任何 flask 代码,以下构建也会失败

FROM python:3.8.10-alpine3.13
RUN pip install cryptography==2.8

Please have a look and let me know if more info is needed or where I am going wrong.请看一下,如果需要更多信息或我哪里出错了,请告诉我。 Thanks谢谢

I think your problem in with alpine linux image, I mean the base image used for building python:3.9.10-alpine3.15 you should try to install cryptography manually by following the code mentioned below:我认为您的问题在于 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 documentation also has the information as how to download it密码学文档也包含如何下载它的信息

RUN apk add gcc musl-dev libffi-dev openssl-dev cargo

There appears to be a problem with the base image as pointed out by @Soheb, it works perfectly with python:3.8.10-slim-buster .正如@Soheb 所指出的,基本映像似乎存在问题,它与python:3.8.10-slim-buster完美配合。 Not too sure what was the issue with the previous base image though虽然不太确定以前的基本图像有什么问题

The issue is that the alpine image does not have gcc installed as you can see in the complete error message (not shown in your question, but easily reproduced with docker):问题是alpine映像没有安装gcc ,正如您在完整的错误消息中看到的那样(未在您的问题中显示,但很容易用 docker 复制):

Unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1

Fix it by installing gcc and the dependencies of cryptography :通过安装 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 

You might still wonder why you get the (confusing ) message:您可能仍然想知道为什么会收到(令人困惑的)消息:

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)

The error message is simply stating the facts: pip could not find a version that错误消息只是陈述事实: pip找不到一个版本

  1. fits your requirements符合您的要求
  2. Could be installed without error可以安装没有错误

The only version that satisfied 1. (and was downloaded, see the complete log of the installation) did not staisfy 2. and was therefore discarded.满足 1. 的唯一版本(并且已下载,请参阅安装的完整日志)没有满足 2. 因此被丢弃。 Then the error is produced with a list of all versions that pip checked against condition 1. and 2., ie all versions on pypi that where candidates for your OS and python version然后产生错误,其中列出了 pip 针对条件 1. 和 2. 检查的所有版本,即 pypi 上的所有版本,其中您的操作系统和 python 版本的候选版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM