Solving DNS Resolution Issues Inside Docker Containers
Sometimes, a Docker container can’t resolve hostnames like example.com or your private APIs — even though they work fine on the host. In this post, you’ll learn why DNS resolution fails inside containers and How To Fix DNS Resolution Issues Inside Docker.
What Is DNS Resolution in Docker?
DNS (Domain Name System) translates domain names into IP addresses. Inside Docker containers, DNS resolution depends on:
- Docker’s internal DNS system (
127.0.0.11) - The host machine’s DNS configuration
- Network mode and bridge behavior
When something goes wrong, containers can’t access the internet or other services via domain names.
Common Symptom
You run this inside a container:
ping example.com
And get:
ping: example.com: Temporary failure in name resolution
Or in Python:
import requests
requests.get("https://example.com")
And see:
requests.exceptions.ConnectionError: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution
Step-by-Step To Fix DNS Resolution Issues Inside Docker
1. Check If the Container Has Internet
Run this:
docker run busybox nslookup example.com
If you get:
nslookup: can't resolve 'example.com': Name does not resolve
→ There’s a DNS problem.
If it returns an IP → DNS works!
2. Manually Set DNS Server in Docker Run
Try using Google DNS (8.8.8.8):
docker run --dns=8.8.8.8 busybox nslookup example.com
If it works, the issue is your Docker daemon’s default DNS config.
3. Fix DNS for All Containers via Daemon Config
Edit or create the Docker daemon configuration file:
Linux/Mac:
/etc/docker/daemon.json
Windows:
C:\ProgramData\Docker\config\daemon.json
Add this:
{
"dns": ["8.8.8.8", "8.8.4.4"]
}

Then restart Docker:
# Linux/macOS:
sudo systemctl restart docker
# Windows:
Restart Docker Desktop from the system tray
4. Use Host Network (Linux-only)
If your container needs the exact DNS config of your host:
docker run --network host busybox nslookup example.com
⚠️ Only works on Linux — not Docker Desktop for Mac/Windows.
Why This Happens
- Docker uses its own embedded DNS server (
127.0.0.11) - If your host’s
/etc/resolv.confhas problems (e.g. systemd-resolved, VPN conflicts), containers inherit it - Docker Desktop (on Windows/macOS) may behave differently based on WSL2 or Hyper-V
Summary
| Problem | Solution |
Temporary failure in resolution | Use --dns=8.8.8.8 or fix daemon DNS |
| Container can’t reach domains | Check /etc/resolv.conf |
| VPN interferes with DNS | Restart Docker, try public DNS |
DNS resolution issues in Docker are common — but once you know how Docker handles DNS, they’re easy to troubleshoot. Whether you’re running Python scripts, curl, or full-stack apps, setting the correct DNS can save hours of debugging.
This is the end of the Solving DNS Resolution Issues Inside Docker Containers.
You can read more useful articles like How to Fix ‘Bind for 0.0.0.0:80 Failed’ Error in Docker.
Follow us for the more helpful posts!
We hope this is a useful post for you.