apt-get install fails during docker build — network or DNS issue in builder
docker build fails at RUN apt-get install with 'Could not resolve archive.ubuntu.com'
Focused incident mode — strips away everything but this runbook.
Symptoms
- docker build fails at RUN apt-get install with 'Could not resolve archive.ubuntu.com'
- Err:1 http://archive.ubuntu.com/ubuntu ... Temporary failure in name resolution
- docker build hangs on apt-get update then times out
docker build --network=host is a fast way to isolate DNS/network issues from Docker's bridge networking. If it works, the problem is Docker's DNS, not the upstream network.
Evidence to grab
Collect these artifacts before you change anything — they prove (or rule out) each cause.
Build error output
docker build . 2>&1 | tail -30Docker build DNS config
docker build --network=host . 2>&1 | tail -5
Diagnostic flow
Run the steps in order, marking each claim confirmed or refuted. The evidence you gather feeds the ranked causes below.
Guided decision tree is ready.
Steps with commands, expected output, and pass/fail branches.
Ranked root causes
Evidence checklist
- docker build fails with name resolution error
- docker build --network=host works
- daemon.json has no dns or wrong dns setting
Confirm before fixing
docker run --rm alpine nslookup archive.ubuntu.comTest DNS from a container on the default bridge
Expected: Address: 91.189.91.x
Fix
echo '{"dns": ["8.8.8.8", "8.8.4.4"]}' | sudo tee /etc/docker/daemon.json && sudo systemctl restart dockerSet DNS servers in Docker daemon config
Resolution runbook
Apply from top to bottom after the cause is confirmed. Review every command before running it — risk tags are shown on each.
docker build --network=host . 2>&1 | tail -20Test if host network fixes the build
cat /etc/docker/daemon.json 2>/dev/null || echo 'No daemon.json'Check daemon DNS config
echo '{"dns": ["8.8.8.8", "8.8.4.4"]}' | sudo tee /etc/docker/daemon.jsonSet DNS servers globally for Docker
sudo systemctl restart dockerRestart Docker to pick up the new DNS config
Prevention
- Configure DNS in /etc/docker/daemon.json: {"dns": ["8.8.8.8", "8.8.4.4"]}.
- Use multi-stage builds to reduce the number of apt-get calls per layer.
- Pin Ubuntu/Debian base images to avoid repo expiration.
- Pass proxy env vars via --build-arg in CI/CD pipelines behind corporate proxies.
Related runbooks
Same stack, same failure family — worth a skim.
ping: Temporary failure in name resolution inside the container
Sending build context to Docker daemon X.XXMB/GB takes minutes
Commands marked READ CHANGE DESTRUCTIVE — never run DESTRUCTIVE commands against production data you cannot restore. Copy → verify → execute.