⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Docker & Containers Interview Questions Scenario 24 of 159 in Docker & Containers
Senior DevOps / SRE [L2] Docker Production Scenario [L2]
🎯 Target Role / Context: Docker Scenario #24 (L2) · Docker

Q: Your container image build is failing on `apt-get update`. What's likely wrong?

A build failing on apt-get update is usually a network or repository problem, not an apt bug: DNS or proxy settings inside the build, an end-of-life release whose repos moved, an expired or missing GPG key, or a clock mismatch.

#Docker #L2 #Containers #Linux
🎙️ Candidate Opening & Architectural Context
"A <strong>build failing on apt-get update</strong> is usually a network or repository problem, not an apt bug: DNS or proxy settings inside the build, an end-of-life release whose repos moved, an expired or missing GPG key, or a clock mismatch. Interviewers ask it to see whether you troubleshoot in order, using the exact error text rather than guessing. The runbook is to reproduce outside the build, read the specific error, isolate network from repository issues, fix the root cause and then harden the Dockerfile so it stays reliable."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's Docker Certified Associate (DCA) Hands-On Lab Course covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: A <strong>build failing on apt-get update</strong> is usually a network or repository problem, not an apt bug: DNS or proxy settings inside the build, an end-of-life release whose repos moved, an expired or missing GPG key, or a clock mismatch. Interviewers ask it to see whether you troubleshoot in order, using the exact error text rather than guessing. The runbook is to reproduce outside the build, read the specific error, isolate network from repository issues, fix the root cause and then harden the Dockerfile so it stays reliable.

1️⃣

Symptom to cause map

Start from the message, because each one points at a different layer.

  • Temporary failure resolving 'deb.debian.org': DNS. The build container cannot resolve names, often due to a corporate resolver or a broken /etc/docker/daemon.json DNS setting.
  • Could not connect / connection timed out: proxy, firewall, or an IPv6 route that does not work.
  • 404 Not Found or 'does not have a Release file': the distribution is end of life and its repos moved. For example EOL Debian releases go to archive.debian.org and EOL non-LTS Ubuntu releases to old-releases.ubuntu.com.
  • NO_PUBKEY, invalid signatures, 'Release file is not valid yet': missing or expired key, or clock skew, often on a Docker Desktop VM after sleep.
  • Hash Sum mismatch: a caching proxy or mirror in the middle serving partial content.
2️⃣

Hands-on: reproduce a build failing on apt-get update

Remove Docker build noise and test the failing step in isolation. Change one variable at a time so the result is attributable.

docker build --progress=plain --no-cache -t test .

docker run --rm -it debian:bookworm bash -c 'apt-get update'
docker run --rm busybox nslookup deb.debian.org
docker run --rm curlimages/curl -sSI https://deb.debian.org

# Is it Docker's bridge network?
docker build --network host -t test .
  • Full output: rerun with docker build --progress=plain --no-cache . to see every line and bypass a cached bad layer.
  • Same base, interactively: run the base image and execute the command by hand.
  • Test DNS and connectivity: check resolution and an HTTPS fetch from a throwaway container.
  • Try the host network: docker build --network host . tells you whether Docker's bridge networking is the culprit.
  • Architecture mismatch: on ARM builders or emulated builds some third-party repositories do not publish the architecture you need, and apt-get update warns or fails for that source only. Check dpkg --print-architecture.
Advertisement
3️⃣

Fix the root cause

Apply the fix that matches the diagnosis.

# Stopgap for an EOL Debian release (prefer upgrading the base image)
RUN sed -i 's|deb.debian.org|archive.debian.org|g' /etc/apt/sources.list

# Proxy at build time
# docker build --build-arg HTTPS_PROXY=http://proxy.example.com:3128 .
  • DNS: set resolvers in /etc/docker/daemon.json (for example {"dns": ["10.0.0.2", "8.8.8.8"]} using your resolver), then restart the daemon.
  • Proxy: pass --build-arg HTTP_PROXY=... --build-arg HTTPS_PROXY=.... These are predefined build args and do not need an ARG line. Add your corporate CA with ca-certificates if TLS is intercepted.
  • EOL release: the real fix is a supported base image tag. As a stopgap point sources at the archive host.
  • Clock or keys: restart Docker Desktop to resync the VM clock. For third-party repos, install the signing key into /etc/apt/keyrings with signed-by= instead of the deprecated apt-key.
  • IPv6 problems: if the build host has a broken IPv6 route, apt may hang trying AAAA addresses first. Forcing IPv4 with -o Acquire::ForceIPv4=true confirms it as the cause.
4️⃣

Harden the Dockerfile pattern

Many intermittent failures come from how the step is written. Treat the Dockerfile as code that runs on many networks, not only yours.

RUN apt-get update -o Acquire::Retries=3 \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
      ca-certificates curl \
 && rm -rf /var/lib/apt/lists/*
  • Combine in one layer: apt-get update && apt-get install in one RUN. A separate cached update layer goes stale and later installs hit 404 on outdated package indexes.
  • Non-interactive: set DEBIAN_FRONTEND=noninteractive for the step only and use -y.
  • Retries: -o Acquire::Retries=3 smooths over transient mirror hiccups.
  • Clean up: remove /var/lib/apt/lists/* in the same layer to keep the image small.
  • Ownership of the fix: network and proxy issues belong to platform or network teams, so bring them the exact failing hostname and command output rather than a vague report that the build is broken.
5️⃣

Verification and prevention

Confirm the fix and keep it from recurring.

  • Verify: a clean docker build --no-cache passes, and CI passes on a fresh runner, not only on your cached laptop.
  • Mirror dependencies: use an internal package mirror or pull-through registry so builds do not depend on public mirrors.
  • Track base image EOL: schedule base image upgrades and scan for unsupported distributions.
  • Pin and rebuild regularly: pin base images by digest and rebuild weekly so repo drift shows up early.
  • BuildKit secrets: if a private repository needs credentials, pass them with a BuildKit secret mount, never as a build argument that gets stored in image history.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Always copy the first error line from <code>--progress=plain</code> output. DNS, EOL repo and GPG errors look similar in a failing build but need entirely different fixes."
⚡ 60-Second Elevator Pitch Talking Points
  • I reproduce the failure with <code>--progress=plain --no-cache</code> and by running <code>apt-get update</code> by hand in the base image.
  • I classify by message: DNS or proxy, EOL repositories, GPG or clock, or a bad mirror, and test DNS and HTTPS from a throwaway container.
  • I fix the cause, keep update and install in a single layer with retries, and use a supported, pinned base image with an internal mirror.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Putting apt-get update in its own RUN layer The layer is cached, so a later install can use a stale index and fail with 404 errors.
  2. Staying on an EOL base image and patching sources forever Repos move and eventually stop updating, so security fixes are gone. Upgrade the base image.
  3. Using apt-key add or disabling signature checks apt-key is deprecated and bypassing signatures removes supply-chain protection. Use signed-by keyrings.
  4. Debugging only with cached builds A cached layer hides the failure on your machine while a clean CI runner breaks. Use --no-cache when diagnosing.
Advertisement
Want more Docker & Containers scenarios?
Explore our complete collection of scenario-based Docker & Containers interview runbooks.
Browse All Docker & Containers Questions →