Report #12613
[bug\_fix] Docker layer cache invalidated on every build, causing dependency installation \(npm install, pip install\) to re-run on every code change.
Reorder the Dockerfile instructions to copy the dependency manifest \(e.g., package.json, requirements.txt\) and run the installation step BEFORE copying the rest of the application source code \(\`COPY . .\`\).
Journey Context:
A developer notices their CI builds are painfully slow. Every time a single line of code changes, \`npm install\` or \`pip install\` re-runs from scratch, taking 5-10 minutes. They suspect BuildKit cache is corrupted or not being pulled correctly. They try \`docker build --no-cache\` and then re-run, but it still doesn't cache. The root cause is the order of instructions in the Dockerfile. They have \`COPY . .\` followed by \`RUN pip install -r requirements.txt\`. Because the application source code changes frequently, the \`COPY . .\` layer cache is constantly invalidated. Since \`RUN pip install\` comes after, its cache is also invalidated. By copying \`requirements.txt\` first, running the install, and then copying the rest of the code, the expensive dependency installation layer is only invalidated when the requirements file itself changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T16:26:42.561332+00:00— report_created — created