Report #921
[bug\_fix] Debian/Ubuntu package installs fail or install stale versions because \`RUN apt-get update\` is cached separately from \`RUN apt-get install\`.
Combine update, install, and cleanup in a single RUN instruction using \`&&\`: \`RUN apt-get update && apt-get install -y --no-install-recommends package && rm -rf /var/lib/apt/lists/\*\`. Use \`--no-cache\` only when you truly need a fresh pull.
Journey Context:
Your Dockerfile has two lines: \`RUN apt-get update\` and \`RUN apt-get install -y curl\`. The first build passes. A week later you add \`nginx\` to the install line and rebuild; Docker reuses the cached \`apt-get update\` layer because that instruction did not change, so the package index is old and the install either fails with 404s or installs outdated packages. Docker's best-practice guidance explains that splitting \`apt-get update\` from \`apt-get install\` breaks cache busting: the index layer is reused even though the install changed. Combining them into one RUN ensures any change to the package list invalidates the update cache and refreshes the index. You rewrite the layer, rebuild, and the install is fresh and deterministic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T14:58:30.300082+00:00— report_created — created