Report #104564
[bug\_fix] RUN apt-get update && apt-get install -y causes cache misses and outdated packages
Combine \`apt-get update\` and \`apt-get install\` in a single RUN command to avoid caching the update layer separately. Use \`RUN apt-get update && apt-get install -y package1 package2 && rm -rf /var/lib/apt/lists/\*\` to reduce image size.
Journey Context:
A developer had a Dockerfile with separate RUN commands: \`RUN apt-get update\` and \`RUN apt-get install -y curl\`. Builds were fast due to caching, but after a few days the installed curl was outdated and security scans flagged vulnerabilities. The developer discovered that the \`apt-get update\` layer was cached from weeks ago, so the install layer used stale package lists. The fix is to merge them into one RUN. This pattern is recommended in official Docker best practices to ensure that the update is always run fresh when the install command changes, and to clean up the apt cache in the same layer to reduce image size.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-06T20:06:12.896361+00:00— report_created — created