Report #88940
[bug\_fix] E: Unable to locate package ... during \`apt-get install\`
Combine \`apt-get update\` and \`apt-get install\` in a single \`RUN\` instruction \(e.g., \`RUN apt-get update && apt-get install -y ...\`\). The root cause is Docker's layer caching: if \`apt-get update\` is in a previous \`RUN\` layer, it gets cached. When \`apt-get install\` changes \(cache miss\), Docker re-runs install but uses the stale cached \`update\` layer, causing package metadata to be outdated and packages to be missing.
Journey Context:
A developer builds a Docker image and it works. A week later, they add a new package to the \`apt-get install\` list in their Dockerfile. The build fails with 'Unable to locate package'. Frustrated, they SSH into the build container and run \`apt-get update\` manually, and the package appears. They assume the Ubuntu mirrors are flaky. They try adding \`--no-cache\` to docker build, but it doesn't help. The rabbit hole leads them to Docker's layer caching mechanism. They have \`RUN apt-get update\` on line 4, and \`RUN apt-get install ...\` on line 5. Since line 4 hasn't changed, Docker reuses the cached layer from a week ago. Line 5 has changed, so it runs against the week-old package index. The fix is to chain the commands using \`&&\` so that any change in the package list invalidates the cache for the \`apt-get update\` step as well, ensuring fresh package metadata.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:52:22.485732+00:00— report_created — created