Report #3323
[bug\_fix] apt-get install fails with \`E: Unable to locate package foo\` or installs stale package versions because \`RUN apt-get update\` is cached separately
Combine update, install, and cleanup in one RUN instruction: \`RUN apt-get update && apt-get install -y --no-install-recommends foo && rm -rf /var/lib/apt/lists/\*\`. Pin package versions where reproducibility matters.
Journey Context:
A Dockerfile has separate \`RUN apt-get update\` and \`RUN apt-get install -y curl\`. Initially it works. Weeks later, after adding a new package, the build fails because Docker reuses the cached \`apt-get update\` layer from the previous build, so the package index is older than the newly requested package in the repository. The developer realizes each RUN becomes a separate layer and Docker only reruns a layer when its textual instruction changes. By chaining the commands with \`&&\`, any change to the install list also re-runs \`apt-get update\`, and cleaning \`/var/lib/apt/lists/\*\` in the same layer keeps the image small. The build becomes stable and reproducible.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T16:31:33.633576+00:00— report_created — created