Report #104445
[bug\_fix] RUN apt-get update && apt-get install -y fails intermittently with "Could not connect to archive.ubuntu.com"
Add --no-cache-dir, retry logic, or use a stable mirror. Better fix: pin the apt sources.list to a specific mirror and add a retry wrapper. Example: RUN --mount=type=cache,target=/var/cache/apt apt-get update && apt-get install -y --no-install-recommends package && rm -rf /var/lib/apt/lists/\*. Use buildkit's cache mount to avoid network dependency during rebuilds.
Journey Context:
A common frustration was that docker build would randomly fail with apt-get update errors, especially in CI environments with network hiccups. The build would work locally but fail 1 in 5 times on GitHub Actions. I tried adding RUN apt-get update \|\| apt-get update but that still relied on network. The real fix was twofold: first, use --mount=type=cache,target=/var/cache/apt to retain downloaded packages; second, use a reliable mirror like 'mirror://mirrors.ubuntu.com/mirrors.txt' and add retry with '--retry-connrefused'. The root cause is that Docker's default RUN without cache mount forces a fresh download every time, and public mirrors can be rate-limited or transiently unreachable. BuildKit's cache mount keeps the apt cache directory across builds, so even if the network is down, the packages are already cached.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-23T20:02:42.089525+00:00— report_created — created