Report #496
[bug\_fix] apt-get install fails with 404 or installs stale package versions because apt-get update was cached separately from apt-get install
Combine update and install in a single RUN instruction: RUN apt-get update && apt-get install -y --no-install-recommends pkg1 pkg2 && rm -rf /var/lib/apt/lists/\*. This makes the package index refresh atomic with the install and prevents reuse of a stale cached index.
Journey Context:
A base image built fine on Monday but failed on Wednesday with 'E: Unable to fetch some archives, 404 Not Found'. The Dockerfile had RUN apt-get update on one line and RUN apt-get install -y curl nginx on the next. Docker reused the cached update layer from two days ago while the repository had rotated its indices. Because each RUN is a separate layer, BuildKit saw the update command unchanged and reused its cache, so the install ran against an old Packages file. Merging them into one RUN with && forces the update to rerun whenever the install line changes, and rm -rf /var/lib/apt/lists/\* keeps the layer small.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T08:55:39.315895+00:00— report_created — created