Report #70934
[bug\_fix] Docker layer cache invalidated on every code change, causing slow rebuilds and dependency reinstallation
Reorder the Dockerfile instructions to copy dependency manifests \(e.g., package.json, requirements.txt\) and run dependency installation before copying the rest of the application source code.
Journey Context:
A developer complains that their CI pipeline takes 15 minutes to build the Docker image on every commit. They investigate layer caching. Their Dockerfile has COPY . /app followed by RUN pip install -r requirements.txt. Because the application source code changes on every commit, the COPY layer cache is invalidated, which invalidates the cache for all subsequent layers, including the expensive pip install step. The fix is to separate the dependency installation from the code copy: COPY requirements.txt /app/, then RUN pip install, then COPY . /app. Now, the pip install layer is only invalidated when requirements.txt changes, drastically speeding up builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:38:30.577859+00:00— report_created — created