Alpine python 3.7.7 docker:pipenv 无法安装 psycopg2 2.8.4 和 pyzmq 而在 python 3.7.3 的主机上安装正常

Alpine python 3.7.7 docker: pipenv failing to install psycopg2 2.8.4 and pyzmq whereas installs fine on host with python 3.7.3

在我的 archlinux 主机上我有

 python 3.7.3
 pipenv, version 2018.11.26

我有 PipfilePipfile.lock,里面有很多包。我使用 pipenv install --dev

在 vi​​rtualenv 中安装所有包

我有 psycopg2 2.8.4pyzmq 软件包,它们也可以毫无错误地安装。

但是在 docker python:3.7.7-alpine3.11 中,我无法安装来自 PipfilePipfile.lock 的所有软件包。

psycopg2 2.8.4pyzmq 软件包未安装并抛出错误。

pyzmq 里面 Pipfile.lock

"pyzmq": {
    "hashes": [
        "sha256:01b588911714a6696283de3904f564c550c9e12e8b4995e173f1011755e01086",
        "sha256:0573b9790aa26faff33fba40f25763657271d26f64bffb55a957a3d4165d6098",
        "sha256:0fa82b9fc3334478be95a5566f35f23109f763d1669bb762e3871a8fa2a4a037",
        "sha256:1e59b7b19396f26e360f41411a5d4603356d18871049cd7790f1a7d18f65fb2c",
        "sha256:2a294b4f44201bb21acc2c1a17ff87fbe57b82060b10ddb00ac03e57f3d7fcfa",
        "sha256:355b38d7dd6f884b8ee9771f59036bcd178d98539680c4f87e7ceb2c6fd057b6",
        "sha256:4b73d20aec63933bbda7957e30add233289d86d92a0bb9feb3f4746376f33527",
        "sha256:4ec47f2b50bdb97df58f1697470e5c58c3c5109289a623e30baf293481ff0166",
        "sha256:5541dc8cad3a8486d58bbed076cb113b65b5dd6b91eb94fb3e38a3d1d3022f20",
        "sha256:6fca7d11310430e751f9832257866a122edf9d7b635305c5d8c51f74a5174d3d",
        "sha256:7369656f89878455a5bcd5d56ca961884f5d096268f71c0750fc33d6732a25e5",
        "sha256:75d73ee7ca4b289a2a2dfe0e6bd8f854979fc13b3fe4ebc19381be3b04e37a4a",
        "sha256:80c928d5adcfa12346b08d31360988d843b54b94154575cccd628f1fe91446bc",
        "sha256:83ce18b133dc7e6789f64cb994e7376c5aa6b4aeced993048bf1d7f9a0fe6d3a",
        "sha256:8b8498ceee33a7023deb2f3db907ca41d6940321e282297327a9be41e3983792",
        "sha256:8c69a6cbfa94da29a34f6b16193e7c15f5d3220cb772d6d17425ff3faa063a6d",
        "sha256:8ff946b20d13a99dc5c21cb76f4b8b253eeddf3eceab4218df8825b0c65ab23d",
        "sha256:972d723a36ab6a60b7806faa5c18aa3c080b7d046c407e816a1d8673989e2485",
        "sha256:a6c9c42bbdba3f9c73aedbb7671815af1943ae8073e532c2b66efb72f39f4165",
        "sha256:aa3872f2ebfc5f9692ef8957fe69abe92d905a029c0608e45ebfcd451ad30ab5",
        "sha256:cf08435b14684f7f2ca2df32c9df38a79cdc17c20dc461927789216cb43d8363",
        "sha256:d30db4566177a6205ed1badb8dbbac3c043e91b12a2db5ef9171b318c5641b75",
        "sha256:d5ac84f38575a601ab20c1878818ffe0d09eb51d6cb8511b636da46d0fd8949a",
        "sha256:e37f22eb4bfbf69cd462c7000616e03b0cdc1b65f2d99334acad36ea0e4ddf6b",
        "sha256:e6549dd80de7b23b637f586217a4280facd14ac01e9410a037a13854a6977299",
        "sha256:ed6205ca0de035f252baa0fd26fdd2bc8a8f633f92f89ca866fd423ff26c6f25",
        "sha256:efdde21febb9b5d7a8e0b87ea2549d7e00fda1936459cfb27fb6fca0c36af6c1",
        "sha256:f4e72646bfe79ff3adbf1314906bbd2d67ef9ccc71a3a98b8b2ccbcca0ab7bec"
    ],
    "version": "==18.1.1"

psycopg2 里面 Pipfile.lock

"psycopg2": {
    "hashes": [
        "sha256:4212ca404c4445dc5746c0d68db27d2cbfb87b523fe233dc84ecd24062e35677",
        "sha256:47fc642bf6f427805daf52d6e52619fe0637648fe27017062d898f3bf891419d",
        "sha256:72772181d9bad1fa349792a1e7384dde56742c14af2b9986013eb94a240f005b",
        "sha256:8396be6e5ff844282d4d49b81631772f80dabae5658d432202faf101f5283b7c",
        "sha256:893c11064b347b24ecdd277a094413e1954f8a4e8cdaf7ffbe7ca3db87c103f0",
        "sha256:92a07dfd4d7c325dd177548c4134052d4842222833576c8391aab6f74038fc3f",
        "sha256:965c4c93e33e6984d8031f74e51227bd755376a9df6993774fd5b6fb3288b1f4",
        "sha256:9ab75e0b2820880ae24b7136c4d230383e07db014456a476d096591172569c38",
        "sha256:b0845e3bdd4aa18dc2f9b6fb78fbd3d9d371ad167fd6d1b7ad01c0a6cdad4fc6",
        "sha256:dca2d7203f0dfce8ea4b3efd668f8ea65cd2b35112638e488a4c12594015f67b",
        "sha256:ed686e5926929887e2c7ae0a700e32c6129abb798b4ad2b846e933de21508151",
        "sha256:ef6df7e14698e79c59c7ee7cf94cd62e5b869db369ed4b1b8f7b729ea825712a",
        "sha256:f898e5cc0a662a9e12bde6f931263a1bbd350cfb18e1d5336a12927851825bb6"
    ],
    "index": "pypi",
    "version": "==2.8.4"

当我尝试在 docker 中安装来自 PipfilePipfile.lock 的软件包时,出现以下错误

我在某处读到它的问题是 gcc 编译器在 alpine 中不可用。所以我也尝试了 RUN apk --no-cache add build-base

的 Dockerfile
FROM python:3.7.7-alpine3.11

ENV PYTHONUNBUFFERED 1

RUN apk --no-cache add build-base

还是一样的错误

既然它安装在 archlinux 上,为什么它没有安装在我的 docker 图像上。

我想在我的各种项目中保持相同的配置(python 3.7 和相同的 Pipfile 和 Pipfile.lock),如何在 docker[=37= 中完成此操作]

尝试将此添加到 Dockerfile:

RUN apk update \
  # psycopg2 dependencies
  && apk add --virtual build-deps gcc python3-dev musl-dev \
  && apk add postgresql-dev \
  # pyzmq dependencies
  && apk add build-base libzmq musl-dev zeromq-dev

看看: How to install pyzmq on a Alpine Linux container?

Alpine 图像很轻,但也有缺点。