带有pip grpcio的Dockerfile的构建速度非常慢

Ind*_*ing 6 python pip docker dockerfile

我有一个需要安装一些pip软件包的Dockerfile。其中一些需要grpcio,仅花费几分钟即可构建此部分。有没有人建议加快这一部分?

Installing collected packages: python-dateutil, azure-common, azure-nspkg, azure-storage, jmespath, docutils, botocore, s3transfer, boto3, smmap2, gitdb2, GitPython, grpcio, protobuf, googleapis-common-protos, grpc-google-iam-v1, pytz, google-api-core, google-cloud-pubsub
Found existing installation: python-dateutil 2.7.3
  Uninstalling python-dateutil-2.7.3:
    Successfully uninstalled python-dateutil-2.7.3
Running setup.py install for grpcio: started
Running setup.py install for grpcio: still running...
Running setup.py install for grpcio: still running...
Running setup.py install for grpcio: still running...
Run Code Online (Sandbox Code Playgroud)

谢谢。

iva*_*ncz 22

我遇到了同样的问题,通过升级 pip 解决了:

$ pip3 install --upgrade pip
Run Code Online (Sandbox Code Playgroud)

这是 grpc 项目的一位维护者的话:

  • 你让我今天一整天都感觉很好! (3认同)

PhE*_*PhE 8

有同样的问题,通过使用 virtualenv 和多级 dockerfile 修复它:

FROM python:3.7-slim as base

# ---- compile image -----------------------------------------------
FROM base AS compile-image
RUN apt-get update \
  && apt-get install -y --no-install-recommends \
  build-essential \
  gcc

RUN python -m venv /app/env
ENV PATH="/app/env/bin:$PATH"

COPY requirements.txt .
RUN pip install --upgrade pip
# pip install is fast here (while slow without the venv) :
RUN pip install -r requirements.txt

# ---- build image -----------------------------------------------
FROM base AS build-image
COPY --from=compile-image /app/env /app/env

# Make sure we use the virtualenv:
ENV PATH="/app/env/bin:$PATH"
COPY . /app
WORKDIR /app

Run Code Online (Sandbox Code Playgroud)

这是我的 requirements.txt :

fastapi==0.27.*
grpcio-tools==1.21.*
uvicorn==0.7.*
Run Code Online (Sandbox Code Playgroud)

  • 我很好奇为什么 virtualenv 会在这里产生影响。 (7认同)