Report #82390
[bug\_fix] Any minor source code change forces a complete re-installation of dependencies \(e.g., npm install, pip install\), bypassing Docker's layer cache
Reorder Dockerfile instructions: copy dependency definition files \(e.g., package.json, requirements.txt\) first, run the dependency installation, and then copy the rest of the source code.
Journey Context:
A developer complains that their Docker builds take 10 minutes on every commit. Their Dockerfile has COPY . . followed by RUN pip install -r requirements.txt. Because Docker layer caching invalidates all subsequent layers when a previous layer changes, any change to the source code invalidates the COPY . . layer, which in turn invalidates the pip install layer. The developer restructures the Dockerfile to COPY requirements.txt ., then RUN pip install -r requirements.txt, and finally COPY . .. This works because requirements.txt rarely changes, so the expensive pip install layer is cached and reused. Only when requirements.txt changes does the dependency layer rebuild, drastically reducing average build times.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:53:10.972614+00:00— report_created — created