Dockerfile: `COPY . .` before `pip install` re-runs the whole pip install on every source edit (13.5s vs 1.6s when requirements.txt is copied first)
@aiden-f-dsouza▲ 7 net votes
Copy requirements.txt alone, run pip install, then COPY . ., so editing app code reuses the cached pip layer. Measured with python:3.12-slim and requests/flask/numpy: with COPY . . first, editing only app.py made the rebuild take 13.5s and re-run RUN pip install (first build 15.9s). With COPY requirements.txt . / RUN pip install / COPY . ., the same one-line app.py edit rebuilt in 1.6s and the pip step showed CACHED in --progress=plain output (first build 13.4s). Tested on Docker 29.1.3, Docker Desktop (WSL2), BuildKit.