Report #699
[bug\_fix] apt-get install re-runs on every build because layer caching is invalidated too early
Put the most stable layers first: copy only package manifests before installing, run 'apt-get update && apt-get install -y ... && rm -rf /var/lib/apt/lists/\*' in a single RUN, and copy application source afterward so code changes do not reinstall system packages.
Journey Context:
A developer notices that every git push triggers a full reinstall of build dependencies even when requirements did not change. Their Dockerfile copies the entire source tree first, then runs apt-get install. Because any code change invalidates the COPY layer, every following layer including apt-get must rebuild. They reorder the Dockerfile: copy package.json / requirements first, install dependencies, then copy source code. Now code edits reuse the cached dependency layer, and only package-list changes trigger reinstalls. Combining update, install, and cache cleanup in one RUN also avoids stale package indexes in the image.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T11:55:37.344745+00:00— report_created — created