Docker Build DNS Lookup Error: Fix Connection Issues
In this article
This error means Docker cannot resolve domain names during the build process. Restarting the Docker Desktop application or checking your network proxy settings usually resolves it immediately.
Time 5 min · Steps 4 · Level Easy
Diagnose and Resolve Network Connectivity Problems
- Check Proxy Settings: Ensure your environment variables for HTTP_PROXY are correct or unset if not using a corporate proxy.
- Restart the Service: Stop and start the Docker Desktop daemon to clear temporary network state glitches.
- Verify DNS Configuration: Confirm that your system's DNS servers are reachable and responding to queries.
- Test with Base Image: Attempt to pull a simple image like
alpineto isolate if the issue is specific to a registry.
The "DNS lookup failed" error occurs when the Docker daemon, running inside a lightweight virtual machine on macOS or Windows, cannot translate a domain name (like registry-1.docker.io) into an IP address. This is distinct from a general internet outage; you can likely browse websites in your browser while the build fails. The most common cause is a misconfigured proxy setting inherited from your host operating system, which confuses the isolated Docker networking stack.
Confirming the Proxy Misconfiguration
If you are behind a corporate firewall or using a VPN, your computer may be configured to route traffic through a specific proxy server. Docker builds often inherit these settings via environment variables. If the proxy is down, unreachable, or does not allow connections to Docker Hub, the build will fail with a DNS error. You can check this by opening your terminal and runningenv | grep -i proxy. If you see variables like http_proxy or https_proxy set to an address that no longer works, this is the culprit.
To fix this, you need to tell Docker to ignore these host-level proxies. In Docker Desktop, go to Settings (the gear icon) > Resources > Network. Look for the "HTTP Proxy" field. If it is populated, try clearing it and applying changes. Alternatively, you can pass the --network=host flag to your build command if you are comfortable exposing the build context directly to your host network interface, though this is less secure for sensitive builds.
Verifying DNS Server Reachability
When proxy settings are not the issue, the problem often lies with the DNS servers themselves. Docker uses the DNS servers configured on your host machine. If those servers are slow or blocking Docker Hub, lookups fail. A reliable public DNS service like Google DNS (8.8.8.8) or Cloudflare DNS (1.1.1.1) often resolves these issues faster than ISP-provided servers.You can test if your current DNS is working by running nslookup registry-1.docker.io in your terminal. If this command hangs or returns a "server failed" message, your DNS configuration is broken. To fix this permanently, update your network adapter settings to use 8.8.8.8 as your primary DNS server. For Docker Desktop specifically, you can also configure custom DNS servers in the Daemon tab under Settings > Docker Engine by adding a line to your JSON configuration:
{
"dns": ["8.8.8.8", "1.1.1.1"]
}
After saving this JSON file, click "Apply & Restart." This forces the Docker daemon to use these specific resolvers regardless of what your host OS reports.
Isolating Registry-Specific Failures
Sometimes the DNS lookup works, but the connection drops during the actual download. This is not a DNS error, but users often confuse the two because the failure happens early in the build process. To distinguish between a pure DNS failure and a connectivity timeout, rundocker pull alpine. If this succeeds, your DNS is fine, and the original error was likely due to a corrupted local cache or a temporary glitch with a specific registry mirror.
If docker pull also fails, check your Docker Desktop status bar. Ensure the engine is actually running and not stuck in a "Starting" loop. On Windows, Hyper-V or WSL2 backend issues can sometimes manifest as network isolation errors. Switching the backend from WSL2 to Hyper-V (or vice versa) in Settings > General can reset the virtual network adapter and resolve persistent lookup failures.
Prevent Future Build Interruptions
To avoid recurring DNS issues, maintain a clean environment variable list. Unset any old proxy variables that point to defunct servers. Regularly update Docker Desktop to ensure the latest networking patches are applied. If you work in a corporate environment, consult your IT department for the correct proxy addresses and whitelist domains required for container registries, such as*.docker.io and gcr.io.
Frequently Asked Questions
Why does docker build work but docker pull fail?
This usually indicates a permissions issue or a missing authentication token rather than a DNS problem. Ensure you are logged in withdocker login. If you are pulling from a private registry, verify that the URL is correct and accessible from your network.
Can I use a local DNS cache to speed up builds?
Yes, installing a local caching DNS resolver like dnsmasq on your host machine can reduce lookup latency. Configure Docker to point to localhost (127.0.0.1) in the Docker Engine settings, and let dnsmasq handle the upstream queries.Official source: Docker Documentation