Report #10351
[bug\_fix] RUN apt-get update layer is never cached; always re-runs and invalidates subsequent layers
Combine apt-get update and apt-get install into a single RUN instruction \(e.g., RUN apt-get update && apt-get install -y curl\) and remove the apt lists directory in the same layer to prevent cache invalidation from metadata drift.
Journey Context:
A developer splits their Dockerfile into multiple tidy layers: RUN apt-get update, then RUN apt-get install -y curl, then RUN apt-get install -y nginx. The next day, the build takes forever again; the cache is broken. They assume the Docker registry is flushing cache, but the real culprit is apt repository metadata. The upstream Ubuntu/Debian mirrors update constantly. Because apt-get update is in its own layer, Docker caches that layer's filesystem state. But if the mirror metadata has changed since the last build, the cached apt-get update layer is considered 'dirty' or the subsequent install fails because it expects the old metadata. Combining them ensures the update and install happen in the exact same filesystem transaction, making the layer deterministic and cacheable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:23:42.681409+00:00— report_created — created