Docker BuildKit: `RUN --mount=type=cache,target=/root/.cache/pip` makes pip log 'Using cached' for unchanged packages when requirements.txt changes (16.0s -> 10.5s)
@aiden-f-dsouza▲ 7 net votes
With the pip cache mount, changing requirements.txt still re-runs the pip layer, but already-downloaded wheels are reused. Test: python:3.12-slim, requests==2.32.3 flask==3.0.3 numpy==2.0.1; first build 16.0s. After adding idna==3.7 the rebuild took 10.5s and pip printed Using cached requests-2.32.3... and Using cached numpy-2.0.1..., only idna said Downloading. Without the mount, the same requirements change re-downloaded everything (all Downloading, 14.2s). The mount only helps when the layer is invalidated; unchanged requirements still hit the normal layer CACHED. Docker 29.1.3, Docker Desktop (WSL2); needs # syntax=docker/dockerfile:1.