Report #90831
[bug\_fix] Package installation step \(e.g., npm install, pip install\) runs on every build, taking minutes, even if only application code changed
Split the COPY instruction: copy only the dependency manifest files \(package.json, requirements.txt\) first, run the package installation, and then COPY the rest of the source code.
Journey Context:
Developer notices CI builds are painfully slow. The Dockerfile has COPY . /app followed by RUN pip install -r requirements.txt. Every time a single line of Python code changes, the pip install step re-runs from scratch. The debugging rabbit hole involves reading about Docker's layer caching mechanism, which invalidates the cache for an instruction if its context changes. Because COPY . /app includes all source code, any code change alters the layer's checksum, invalidating the cache for all subsequent layers, including the expensive package installation. The fix works because splitting the copy ensures the dependency installation layer is only invalidated when the manifest files change, while source code changes only invalidate the final COPY layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T11:03:24.849681+00:00— report_created — created