Immediate Fix: Update the Docker Daemon Configuration
The fastest way to resolve Docker DNS slowness is to bypass the default host-inherited DNS settings and manually define reliable DNS providers in the Docker daemon configuration file.
Open or create the /etc/docker/daemon.json file on your host machine:
sudo nano /etc/docker/daemon.json
Add the following configuration to prioritize Google and Cloudflare DNS, and disable the problematic IPv6 lookup delays:
{
"dns": ["8.8.8.8", "1.1.1.1"],
"dns-opts": ["ndots:0"]
}
After saving the file, restart the Docker service to apply the changes:
sudo systemctl restart docker
Technical Explanation: Why is Docker DNS Slow?
Docker containers usually inherit the /etc/resolv.conf file from the host system. This often includes a high “ndots” value (usually 5) and multiple search domains.
When you try to resolve a simple domain like google.com, the resolver tries it as a subdomain of every entry in your search list first. This creates a cascade of failed lookups before the actual query is sent to the internet.
Another common bottleneck is the “single-request-reopen” issue. Many Linux distributions attempt to perform IPv4 and IPv6 lookups simultaneously. If the firewall or network doesn’t handle these parallel requests correctly, one will timeout, causing a 5-second delay per request.

Alternative Methods to Fix DNS Latency
Depending on your environment, you might prefer to apply fixes at the container level rather than globally via the daemon.
Method 1: Using Docker Compose
If you use Docker Compose, you can define the DNS settings directly in your docker-compose.yml file to ensure portability across different hosts.
services:
app:
image: node:latest
dns:
- 8.8.8.8
- 1.1.1.1
dns_opt:
- use-vc
- ndots:0
Method 2: Runtime CLI Flags
For one-off containers, you can pass the DNS configuration as arguments during the docker run command.
docker run --dns=8.8.8.8 --dns-opt="ndots:0" my-image
Comparison Table of DNS Fixes
| Method | Scope | Best For |
|---|---|---|
| daemon.json | Global | Fixing performance for all local containers. |
| Docker Compose | Project-wide | Standardizing environments for development teams. |
| CLI Flags | Individual Container | Testing and troubleshooting specific issues. |