docker - Docker:在Alpine Linux发行版上安装python加密

标签 docker dockerfile uwsgi alpine python-cryptography

我对Docker和部署周期有点陌生。

我有Django应用程序,我们希望将其与uWSGI一起部署到Docker容器中。实际上,部署可以在数周内完美运行,但现在听起来确实报告了错误...

错误缝与加密软件包有关:

build/temp.linux-x86_64-3.6/_openssl.c:52862:10: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]
build/temp.linux-x86_64-3.6/_openssl.c: In function '_cffi_f_SSL_set_options':
build/temp.linux-x86_64-3.6/_openssl.c:52895:14: warning: conversion to 'long int' from 'long unsigned int' may change the sign of the result [-Wsign-conversion]
   { result = SSL_set_options(x0, x1); }
              ^~~~~~~~~~~~~~~
build/temp.linux-x86_64-3.6/_openssl.c:52895:14: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-dg_tg9pa/cryptography/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-my98rwq4/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-dg_tg9pa/cryptography/ 
The command '/bin/sh -c pip install --no-cache-dir -r requirements.txt' returned a non-zero code: 1
ERROR: Job failed: exit code 1

我们的docker文件看起来像
FROM python:3-alpine

ENV PYTHONUNBUFFERED 1

WORKDIR /usr/src/app

RUN apk add --no-cache gcc mailcap python3-dev build-base linux-headers pcre-dev postgresql-dev libffi-dev libressl-dev

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

正如我提到的那样,在成功构建和失败之间,docker文件和require.txt都没有改变。 (对我来说最奇怪的是...)

我唯一能想到的就是该命令
FROM python:3-alpine

正在使用不同版本的 Alpine ...

这可能吗?有什么事吗如何解决?

最佳答案

对于大多数附带C/C++扩展的Python软件包(用C/C++编写的代码编译为共享对象并通过外部函数库以Python加载),Alpine令人头疼。这样做的原因是PEP 513,它在Linux发行版manylinux1之间的可移植性定义是基于glibc/glibcxx的。由于Alpine使用musl libc,因此Alpine上无法安装manylinux1兼容的转盘。因此,当您发出pip install cryptography时,将过滤具有已编译扩展名的数据包,并且pip会尝试从源代码中使用所有C扩展名来构建软件包。

使用系统软件包管理器进行安装

这是首选方法,@ GracefulRestart在注释中提到了这种方法。如果您不需要该软件包的最新版本,请使用它。用apk安装它:

$ apk add py-cryptography

使用pip安装

如果您需要最新版本,可以尝试通过使用pip安装从源代码构建它。

准备构建环境

您将需要带有头文件的编译器和库:musl,OpenSSL,libffi和Python本身:
$ apk add gcc musl-dev libffi-dev openssl-dev python3-dev

建筑

$ pip install pkgname



默认情况下隐藏构建日志。要查看完整的构建日志,请添加-vvv以增加详细信息。 (可选)此外,您可以通过添加以下命令来明确禁止安装许多Linux1车轮:

-no-binary=pkgname



因此将强制执行从源代码进行的构建。
$ pip install cryptography -vvv --no-binary=cryptography

关于docker - Docker:在Alpine Linux发行版上安装python加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50619166/

相关文章:

使用动态构建从头开始 Dockerfile

bash - 如何在 docker 中的 mongod 之后运行 mongorestore

python - django 和 uwsgi 上的语言环境 UnicodeEncodeError

meteor - 容器退出而不是在后台运行

django - 如何避免使用 Django、nginx 和 uWSGI 将环境变量放到多个地方?

python - Arch Nginx Uwsgi 未加载应用程序

database - Docker Swarm 如何处理数据库(PostgreSQL)复制?

php - Laravel 8 没有读取 docker-compose 传递的环境值

docker - 如何设置 Squid 使其绕过本地网络上客户端的基本身份验证?

node.js - Docker 暴露不工作