Your container builds fine, starts fine, then fails with Could not resolve host or Temporary failure in name resolution. Here’s how to fix it.
Quick Diagnosis
First, confirm it’s actually DNS and not a network issue:
| |
If ping 8.8.8.8 works but nslookup google.com fails, you have a DNS problem. If both fail, it’s a broader network issue.
Common Causes and Fixes
1. Missing or Wrong DNS in resolv.conf
Check what DNS servers the container is using:
| |
If it’s empty or points to 127.0.0.11 (Docker’s embedded DNS) and that’s not working, override it:
| |
2. Host’s DNS Breaking Docker’s Bridge Network
Docker’s default bridge network inherits DNS from the host. If your host uses systemd-resolved (common on Ubuntu 18.04+), the container might see 127.0.0.53 in resolv.conf — which doesn’t work inside the container’s network namespace.
Fix Option A: Configure Docker daemon globally:
| |
Then restart Docker:
| |
Fix Option B: Use host networking (if appropriate):
| |
This makes the container share the host’s network stack entirely. DNS works, but you lose network isolation.
3. Firewall Blocking UDP 53
DNS uses UDP port 53. If your host has aggressive firewall rules, Docker’s traffic might be blocked.
Check with:
| |
Fix by allowing Docker’s bridge network:
| |
4. Corporate Proxy or VPN Interference
If you’re behind a corporate proxy or VPN, the container might need explicit proxy config:
| |
For DNS specifically, your corporate network might require internal DNS servers:
| |
5. Docker Network Corruption
Sometimes Docker’s internal networking state gets corrupted. Nuclear option:
| |
The Fix That Works 90% of the Time
If you just need it working now:
| |
Or add to your docker-compose.yml:
| |
Debugging Script
Save this for future DNS issues:
| |
Run it with:
| |
Summary
| Symptom | Likely Cause | Fix |
|---|---|---|
resolv.conf empty | Docker DNS not configured | Add --dns 8.8.8.8 |
127.0.0.53 in resolv.conf | systemd-resolved conflict | Set DNS in daemon.json |
| Ping works, DNS fails | Firewall blocking UDP 53 | Allow docker0 interface |
| Works on host, not container | Network namespace issue | Try --network host |
DNS issues in Docker are frustrating because they’re silent until runtime. When in doubt, explicit --dns flags are your friend.