[Python] --mount=type=cache doesn't speed up pip install during Docker build

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using --mount=type=cache in my Dockerfile to cache pip packages between builds, but it doesn't seem to have any effect on build speed. I expected pip to reuse cached packages and avoid re-downloading them, but every build takes the same amount of time.

    Here is the relevant part of my Dockerfile:

    FROM python:3.13-slim AS compile-image

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

    RUN pip install --no-cache-dir --upgrade pip


    # Final image
    FROM python:3.13-slim
    ENV PATH="/opt/venv/bin:$PATH"

    COPY --from=compile-image /opt/venv /opt/venv

    WORKDIR /app
    ENV HOME=/app

    COPY . .

    RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
    pip install -e .


    Shouldn't this cache downloaded packages and reuse them in subsequent builds? What could be the reason it's not working as expected?

    Continue reading...

Compartilhe esta Página