Report #15022
[bug\_fix] Dependency installation layer invalidated on every code change
Split the \`COPY\` instruction: copy only the dependency manifest 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 CI pipeline takes 10 minutes on every commit because it reinstalls hundreds of pip/npm packages. They assume Docker caching is broken. They try \`--no-cache\` locally, tweak CI cache settings, but nothing works. They finally realize their Dockerfile has \`COPY . .\` followed by \`RUN pip install -r requirements.txt\`. Because \`COPY . .\` includes all source code, any change to \*any\* file \(even a README\) invalidates the cache for that layer and all subsequent layers, including the pip install. The fix works because Docker evaluates layer caches sequentially. By copying only \`requirements.txt\` first, the pip install layer only invalidates when the requirements file changes, saving massive rebuild time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:56:23.858350+00:00— report_created — created