Report #77410
[bug\_fix] Every source code change invalidates the dependency installation layer \(e.g., npm install, pip install\), causing full reinstalls and drastically increasing build times.
Copy only the 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 notices their Docker builds take 10 minutes, even if they just change a single line of CSS. They examine the build logs and see 'RUN pip install -r requirements.txt' running on every build. They initially suspect Docker's cache is broken. After reading the documentation on layer caching, they realize Docker checks the checksum of the 'COPY . .' layer. Since source code changed, the cache breaks, invalidating all subsequent layers including 'pip install'. They restructure the Dockerfile: 'COPY requirements.txt .', 'RUN pip install', then 'COPY . .'. This works because 'requirements.txt' rarely changes, so the expensive 'pip install' layer is cached and reused. Only the final 'COPY . .' layer is invalidated when source code changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:32:07.162485+00:00— report_created — created