Docker DNS Failure in WSL2: EAI_AGAIN & 127.0.0.11 Fix

25 min readBy Yun Sanghun (M. Yun)

To see how container DNS failures behave on WSL 2, I ran containers on Docker Desktop for Windows 11 (WSL 2 backend, Docker Engine 27.3.1) with an unreachable DNS server (--dns 192.0.2.1) and with a working one (--dns 1.1.1.1). With 192.0.2.1, Python on Debian (glibc) failed after 10 seconds with Temporary failure in name resolution; Python on Alpine (musl) failed after 5 seconds with Try again; Node threw EAI_AGAIN after 5 seconds; curl exited 6 after 11 seconds; and npm view express version took 85 seconds before reporting EAI_AGAIN.

In both debian:bookworm-slim and ubuntu:24.04, apt-get update printed Temporary failure resolving, took 120 seconds, and exited with code 0, so a chained && apt-get install -y curl ran anyway and failed immediately with E: Unable to locate package curl (exit 100). On a user-defined network, /etc/resolv.conf kept nameserver 127.0.0.11, and Docker's embedded DNS server passed the dead upstream straight through and timed out in the same 5 seconds.

Container Symptom / ErrorContainer /etc/resolv.confRoot Cause in Docker / WSL 2Permanent Fix
Temporary failure resolving (apt 120s stall) or Node EAI_AGAIN (5s)nameserver 192.168.65.7 or 127.0.0.11Upstream Windows / WSL 2 forwarder unreachable or dead Wi-Fi switchAdd dns: [1.1.1.1, 8.8.8.8] in Compose or "dns" in daemon.json
1.1.1.1 times out on corporate VPN, intranet names failFallback [8.8.8.8, 8.8.4.4]VPN firewall blocks external UDP port 53 and hides split-DNS resolversSet internal VPN DNS IPs in daemon.json + dnsTunneling=true in .wslconfig
WSL 2 Ubuntu shell itself prints Network is unreachableBroken /etc/resolv.conf symlink in WSLCorrupted Hyper-V virtual switch NAT or disabled auto-generationEnable dnsTunneling=true under [wsl2] and run wsl.exe --shutdown
Peer container hostname fails while deb.debian.org resolvesnameserver 192.168.65.7 (default bridge)Default docker0 bridge disables embedded service-name DNSMove containers onto a user-defined Docker Compose bridge network

Migrating standalone docker run --dns 1.1.1.1 flags into a multi-container stack? Generate the exact Compose dns: and custom bridge YAML with our Docker Run to Compose Converter.

Look at the nameserver, then give the container one that answers

First check what DNS server the container is trying to use, and test whether giving it a reachable server fixes the lookup:

# 1. See what /etc/resolv.conf looks like inside a container
docker run --rm alpine:3.20 cat /etc/resolv.conf

# 2. Test a lookup with an explicit reachable DNS server
docker run --rm --dns=1.1.1.1 alpine:3.20 nslookup deb.debian.org

If the second command works while a plain docker run --rm alpine:3.20 nslookup deb.debian.org times out, set dns on the container or in Docker Compose:

services:
  web:
    image: alpine:3.20
    dns:
      - 1.1.1.1
      - 8.8.8.8
Docker CLI inspecting /etc/resolv.conf (192.168.65.7) and overriding a dead upstream DNS resolver with --dns=1.1.1.1 in Alpine 3.20
Inspecting /etc/resolv.conf inside an Alpine 3.20 container on Docker Engine 27.3.1: when the configured upstream resolver is unreachable (--dns=192.0.2.1), nslookup blocks for 5.04 seconds before exiting with code 1, whereas passing --dns=1.1.1.1 resolves deb.debian.org (151.101.2.132) immediately.
Docker WSL2 DNS resolution topology tracing /etc/resolv.conf nameserver 127.0.0.11 through broken WSL2 stub resolvers versus explicit daemon.json upstream DNS and WSL DNS tunneling
WSL2 Container Resolver Chain: User-defined Compose networks forward container queries through Docker's embedded 127.0.0.11 DNS server; overriding dead WSL2/VPN stub resolvers in /etc/docker/daemon.json or enabling dnsTunneling=true eliminates 5-second lookup stalls.

If your workstation or corporate VPN requires internal company DNS resolvers to resolve private intranet hostnames (or blocks outbound UDP port 53 to public resolvers altogether), list your company's internal DNS server IPs instead of 1.1.1.1 and 8.8.8.8. When you run Docker Engine installed directly inside a WSL 2 Linux distribution (rather than Docker Desktop), you can set those default resolvers once for the entire daemon in /etc/docker/daemon.json:

sudo tee /etc/docker/daemon.json <<'EOF'
{
  "dns": ["1.1.1.1", "8.8.8.8"]
}
EOF
sudo systemctl restart docker

If DNS is broken inside the WSL 2 Linux distribution itself (not only inside Docker containers) on Windows 11 22H2 or 23H2, check that WSL DNS tunneling is enabled in %USERPROFILE%\.wslconfig on the Windows host and restart WSL from PowerShell:

# C:\Users\<your-username>\.wslconfig
[wsl2]
dnsTunneling=true
wsl.exe --shutdown

Note that on Official Docker Desktop, containers on the default bridge receive nameserver 192.168.65.7 while containers on user-defined or Compose networks receive nameserver 127.0.0.11 with upstream resolvers listed under # ExtServers:

Split comparison of container /etc/resolv.conf on Docker default bridge (192.168.65.7) versus user-defined Compose network (127.0.0.11 and # ExtServers)
Contrasting container /etc/resolv.conf generation on Docker Engine 27.3.1: containers on the default bridge receive upstream nameservers directly (192.168.65.7), while containers on user-defined or Compose networks always point to Docker's embedded DNS server (127.0.0.11) and store upstream resolvers in the # ExtServers metadata comment.

Alpine's nslookup gave up after 5 seconds on both networks

On my Windows 11 Pro 23H2 machine running Official Docker Desktop (Docker Engine 27.3.1, WSL 2 backend kernel 6.6.87.2-microsoft-standard-WSL2), normal container DNS lookups were healthy out of the box. To observe and time how containers behave when their upstream DNS resolver stops answering (as happens when a corporate VPN rewrites host routes or a Windows firewall policy drops NAT UDP port 53 packets) the test run on 2025-01-26 passed --dns 192.0.2.1.

Address 192.0.2.1 belongs to 192.0.2.0/24 (TEST-NET-1 in RFC 5737), a documentation-only IPv4 range that is never routed on the public internet, so UDP port 53 queries sent to it receive no reply and force a clean resolver timeout across both default bridge and user-defined networks:

Five-case empirical Docker DNS verification showing default bridge, user network, lost Dockerfile RUN echo into /etc/resolv.conf, and 5-second timeout
The default bridge uses 192.168.65.7 and a user-defined network uses 127.0.0.11. A RUN echo into /etc/resolv.conf is present during the image build step and overwritten at container run time, while an unreachable upstream resolver (--dns 192.0.2.1) causes Alpine's nslookup to time out after 5 seconds on both network types.

The five test cases in that capture highlight three behaviors that matter whenever you debug container DNS on WSL 2:

  • Default bridge vs user-defined network (Cases A and B): On the default bridge network, /etc/resolv.conf inside the container had nameserver 192.168.65.7 (Docker Desktop's internal VM forwarder). On a user-defined bridge network, it had nameserver 127.0.0.11 and options ndots:0.
  • A RUN echo into /etc/resolv.conf during docker build was gone at run time (Case C): Appending options single-request-reopen with RUN echo 'options single-request-reopen' >> /etc/resolv.conf in a Dockerfile modified the file only during that single build step. When a container started from the built image, Docker bind-mounted a freshly generated /etc/resolv.conf (nameserver 192.168.65.7), wiping out the build-time line.
  • 5-second timeout on both networks (Cases D and E): With --dns 192.0.2.1, Alpine's nslookup deb.debian.org printed ;; connection timed out; no servers could be reached and exited 1 after 5 seconds on both the default bridge and the user-defined network.

Each runtime words the failure differently, and npm takes 85 s

When I pointed seven common container tools at the same unreachable resolver (--dns 192.0.2.1), every tool failed, but each C library and language runtime printed a different error message and waited for a different multiple of the 5-second base timeout (distinct from mid-download TCP stalls after DNS succeeds, which trigger 15-second socket timeouts in Python pip ReadTimeoutError & wheel caching):

Side-by-side comparison of Debian glibc Python 10-second gaierror versus Alpine musl 5-second Try again and Node.js 85-second npm EAI_AGAIN
Side-by-side runtime exception traces against an unreachable DNS server (--dns 192.0.2.1): Debian glibc 2.36 raises gaierror(-3, 'Temporary failure in name resolution') after 10.0 seconds (two 5-second attempts), whereas Alpine musl 1.2.5 raises gaierror(-3, 'Try again') in 5.0 seconds and Node.js 22 raises EAI_AGAIN (5.0 seconds for dns.lookup, 85.0 seconds across npm retries).
Image / Tool Command Tested Error Text Returned Time to Fail
python:3.13-slim (Debian glibc) socket.getaddrinfo('deb.debian.org', 443) gaierror(-3, 'Temporary failure in name resolution') 10.0 s
python:3.13-alpine (Alpine musl) socket.getaddrinfo('deb.debian.org', 443) gaierror(-3, 'Try again') 5.0 s
node:22-alpine dns.lookup('registry.npmjs.org', ...) Error: getaddrinfo EAI_AGAIN 5.0 s
node:22-alpine (npm) npm view express version npm error code EAI_AGAIN 85 s
alpine:3.20 ping -c 1 google.com ping: bad address 'google.com' (exit=1) 5.0 s
debian:bookworm-slim getent hosts google.com (no output, exit=2) 20 s
alpine + curl curl -sS https://deb.debian.org curl: (6) Could not resolve host: deb.debian.org (Timeout while contacting DNS servers) 11 s

Notice that Temporary failure in name resolution (Debian glibc), Try again (Alpine musl), and EAI_AGAIN (Node.js) are all the exact same underlying resolver return code (EAI_AGAIN = -3); only the human-readable string from gai_strerror() differs between glibc and musl. And because npm retries failed registry lookups with exponential backoff for 85 seconds before printing npm error code EAI_AGAIN, a broken container DNS configuration during npm install or npm ci often looks like a frozen network hang rather than a DNS failure:

Empirical log of unreachable DNS resolver (--dns 192.0.2.1) error strings and elapsed seconds across seven container runtimes and musl --dns-opt
Empirical log summary on Docker Desktop (Engine 27.3.1): comparing --dns 192.0.2.1 versus --dns 1.1.1.1 across default bridge and user networks, exact failure strings and elapsed seconds across seven container runtimes (5.0 s to 85.0 s), and musl versus glibc timeout reductions using --dns-opt.
# Docker Desktop (Engine 27.3.1), Windows 11. 192.0.2.1 = unreachable test resolver. From dns2078b-20250124.txt
network          --dns       container nameserver   result
default bridge   192.0.2.1   192.0.2.1              exit=1 after 5s
default bridge   1.1.1.1     1.1.1.1                exit=0 after 0s
user network     192.0.2.1   127.0.0.11             exit=1 after 5s
user network     1.1.1.1     127.0.0.11             exit=0 after 0s

apt-get update exits 0, and the next line fails

One of the most confusing symptoms of a Docker DNS outage happens inside Debian and Ubuntu image builds or container startup scripts that chain apt-get update && apt-get install -y .... Here is what happened when I ran that exact chain in debian:bookworm-slim and ubuntu:24.04 with --dns 192.0.2.1:

=== debian:bookworm-slim, --dns 192.0.2.1 ===
Err:1 http://deb.debian.org/debian bookworm InRelease
  Temporary failure resolving 'deb.debian.org'
Err:2 http://deb.debian.org/debian bookworm-updates InRelease
  Temporary failure resolving 'deb.debian.org'
Err:3 http://deb.debian.org/debian-security bookworm-security InRelease
  Temporary failure resolving 'deb.debian.org'
Reading package lists...
W: Failed to fetch http://deb.debian.org/debian/dists/bookworm/InRelease  Temporary failure resolving 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
apt-get update exit=0 seconds=120
Reading package lists...
Building dependency tree...
E: Unable to locate package curl
apt-get install curl exit=100 seconds=0
Dockerfile and bash script comparison explaining why apt-get update exits 0 on DNS failure and causes apt-get install to fail with exit code 100
Inspecting the apt-get update exit-code trap in Debian Bookworm and Ubuntu 24.04 containers: because apt-get update logs DNS failures as warnings (W: Failed to fetch) and exits 0 after 120 seconds, shell && chaining proceeds straight into apt-get install and fails with E: Unable to locate package curl (exit 100).

Look closely at the exit codes and timings in that output:

  • apt-get update waited 120 seconds and exited 0: Even though every single repository index failed with Temporary failure resolving 'deb.debian.org' (or 'archive.ubuntu.com' and 'security.ubuntu.com' on ubuntu:24.04), apt-get update treated the failed downloads as warnings (W: Failed to fetch...) and returned exit status 0 after 2 minutes.
  • The && chain did not stop: Because apt-get update exited 0, the shell immediately executed apt-get install -y --no-install-recommends curl. Since the official base images ship with an empty /var/lib/apt/lists/ directory, apt-get install found zero package metadata and exited immediately (0 seconds, exit code 100) with E: Unable to locate package curl. If you only read the final red error line at the bottom of a CI log, it looks like a missing package or bad repository mirror rather than a DNS failure two minutes earlier.
  • With a reachable DNS server, the whole sequence took 3 seconds: On the normal Docker Desktop bridge (192.168.65.7) or with --dns 1.1.1.1, apt-get update finished in 1 second (exit=0) and apt-get install -y --no-install-recommends curl finished in 2 seconds (exit=0).

Note that I ran these tests with docker run so I could pass --dns directly; docker build does not accept a per-build --dns CLI flag and instead uses the Docker daemon's DNS configuration:

Split terminal log of debian:bookworm-slim apt-get update stalling 120 seconds under --dns 192.0.2.1 versus completing in 3 seconds under --dns 1.1.1.1
Empirical comparison in debian:bookworm-slim on Docker Engine 27.3.1: with --dns 192.0.2.1, apt-get update stalls for 120 seconds before exiting 0 and causing apt-get install curl to fail immediately with exit code 100, whereas --dns 1.1.1.1 completes the index update in 1 second and installs curl in 2 seconds.

Where a container's nameserver comes from on WSL2

Before changing configuration files, check which of the two WSL 2 Docker setups you are running, Official Docker Desktop for Windows (with the WSL 2 backend enabled) or Docker Engine installed directly inside a WSL 2 Linux distribution (such as Ubuntu), because they wire container DNS through two different paths:

DOCKER DESKTOP (what I tested)
  container on default bridge  --> /etc/resolv.conf has nameserver 192.168.65.7
  container on user network    --> /etc/resolv.conf has nameserver 127.0.0.11
                                   (Docker's embedded DNS server, forwards upstream)
  Note: Microsoft's WSL networking docs state that Docker Desktop containers
        bypass WSL DNS tunneling.

DOCKER ENGINE INSIDE A WSL DISTRO (from Docker & Microsoft docs)
  container on default bridge  --> Docker copies the distro's /etc/resolv.conf,
                                   strips 127.0.0.53 if present, or falls back
                                   to 8.8.8.8 / 8.8.4.4.
  distro /etc/resolv.conf      --> written by WSL:
                                   - DNS tunneling on (default): 10.255.255.254
                                   - NAT mode without tunneling: Windows host vSwitch

Here is the healthy baseline on Docker Desktop showing how /etc/resolv.conf switches from 192.168.65.7 on the default bridge to 127.0.0.11 as soon as you attach the container to a user-defined network (gfl-dnsnet):

Healthy Docker Desktop WSL 2 baseline showing Alpine 3.19 resolving deb.debian.org via 192.168.65.7 on default bridge and 127.0.0.11 on gfl-dnsnet
Healthy reference capture on Docker Desktop for Windows 11 (WSL 2 backend): an Alpine 3.19 container on the default bridge receives nameserver 192.168.65.7 and resolves deb.debian.org to 151.101.2.132, while attaching to the user-defined network gfl-dnsnet switches /etc/resolv.conf to nameserver 127.0.0.11.

NAT mode, firewalls and VPNs (from Microsoft's docs)

When Docker Engine runs inside a WSL 2 distribution and the distro uses legacy NAT mode without DNS tunneling, WSL writes the Windows host's Hyper-V virtual switch IP into the distro's /etc/resolv.conf and forwards UDP port 53 traffic across that virtual switch. Microsoft's WSL troubleshooting documentation notes two host-level settings that frequently block those NAT DNS packets:

  1. Windows Firewall Group Policy rules blocking virtual switch rules: WSL's host networking service (HNS) creates a local Windows Firewall rule to allow DNS traffic from the Hyper-V virtual switch. If enterprise Group Policy sets AllowLocalFirewallRules : False or AllowInboundRules : False (checked via Get-NetFirewallProfile -PolicyStore ActiveStore in PowerShell), Windows drops inbound UDP port 53 packets from the WSL 2 subnet.
  2. Corporate VPN clients (Cisco AnyConnect, GlobalProtect, Zscaler): Many VPN clients modify Windows interface metrics, install Name Resolution Policy Table (NRPT) rules, or block split-tunnel traffic from secondary local subnets, causing NAT DNS packets from WSL 2 to black-hole as soon as the VPN connects.

Centralizing container logs in a log stream such as OpenObserve (:5080) makes this pattern immediately visible across microservices, every runtime fails at a multiple of 5 seconds until a reachable resolver is configured:

Live OpenObserve v0.14.2 Logs Explorer on port 5080 correlating container DNS timeout events (gaierror, EAI_AGAIN, apt 120s) against 14ms ExtServers recovery
Centralized container DNS telemetry in OpenObserve v0.14.2 (:5080) on Docker Engine 27.3.1: correlating multi-runtime resolver failures (gaierror, EAI_AGAIN, and 120-second apt-get update stalls when upstream UDP/53 is black-holed) against 14 ms NOERROR lookups once reachable ExtServers are configured.

systemd-resolved, 127.0.0.53 and the 8.8.8.8 fallback

If you run Docker Engine directly inside an Ubuntu WSL distribution where systemd is enabled, systemd-resolved manages host DNS and points /etc/resolv.conf at its local loopback stub listener: nameserver 127.0.0.53. When you start a container without explicit --dns flags, Docker builds the container's /etc/resolv.conf from the host file, but it cannot leave 127.0.0.53 inside the container.

Because each bridge container has its own isolated network namespace (netns) with its own private lo loopback interface, sending a DNS query to 127.0.0.53 inside the container queries the container itself (where systemd-resolved is not running), not the WSL host. According to Docker's networking documentation, when Docker sees 127.0.0.53 on the host, it checks /run/systemd/resolve/resolv.conf for real upstream DNS servers. If no non-loopback nameserver remains after filtering, Docker logs No non-localhost DNS nameservers are left in resolv.conf. Using default external servers : [nameserver 8.8.8.8 nameserver 8.8.4.4] and writes Google's public DNS into the container, which immediately times out on corporate networks that block external UDP port 53:

Configuration breakdown of systemd-resolved 127.0.0.53 loopback stripping, /run/systemd/resolve/resolv.conf inspection, and Docker 8.8.8.8 fallback
How Docker handles systemd-resolved loopback stubs: when the host /etc/resolv.conf lists only nameserver 127.0.0.53, Docker reads /run/systemd/resolve/resolv.conf for real upstream servers and, if no non-loopback server remains, falls back to [8.8.8.8 8.8.4.4], which fails on networks that block external UDP port 53.

127.0.0.11 passed the dead upstream straight through

On the default bridge network, Docker writes the upstream DNS servers directly into the container's /etc/resolv.conf. On any user-defined bridge network, including the network that docker compose up creates automatically for a Compose project, Docker instead writes nameserver 127.0.0.11 so containers on the same network can resolve each other by service name (for example, postgres or gfl-redis).

A common misconception is that switching from the default bridge to a user-defined Compose network will by itself cure external DNS failures. When a container queries 127.0.0.11:53 for a name that does not match any container on the attached bridge network, Docker's embedded DNS server forwards the query to the external resolvers listed in the # ExtServers: [...] comment of /etc/resolv.conf. In my test with --network gfl-dnsnet --dns 192.0.2.1, 127.0.0.11 resolved the peer container gfl-redis locally in 2 milliseconds, and then passed the external query for deb.debian.org straight through to 192.0.2.1 and timed out after the exact same 5 seconds:

Split verification on gfl-dnsnet showing 127.0.0.11 resolving internal peer container gfl-redis in 2ms while external lookup to dead # ExtServers times out in 5s
Proving why Docker's embedded DNS server (127.0.0.11) does not rescue a dead upstream: on user-defined network gfl-dnsnet with --dns 192.0.2.1, 127.0.0.11 resolves the peer container name gfl-redis locally in 2 ms, but forwards external lookups to # ExtServers: [192.0.2.1] and times out after 5.0 seconds.

musl read timeout and attempts, but the total wasn't the product

Alpine Linux containers use musl libc instead of GNU glibc. In earlier versions of musl, the resolver queried configured nameservers in parallel and did not implement glibc's single-request or single-request-reopen workarounds for NAT firewalls that drop one packet when IPv4 (A) and IPv6 (AAAA) UDP queries are sent simultaneously from the same source socket.

Even on current Alpine images (python:3.13-alpine, musl 1.2.5), musl and glibc handle /etc/resolv.conf timeout options differently. When I tested socket.getaddrinfo against the unreachable resolver --dns 192.0.2.1 with --dns-opt flags, musl did read timeout and attempts, but its total wait time was bounded by its overall query window rather than multiplying timeout × attempts:

  • No --dns-opt flags: python:3.13-alpine (musl) failed after 5.0 seconds with gaierror(-3, 'Try again'), while python:3.13-slim (glibc) failed after 10.0 seconds (2 attempts × 5 seconds).
  • --dns-opt timeout:1 --dns-opt attempts:1: Both musl and glibc failed after 1.0 second.
  • --dns-opt timeout:2 --dns-opt attempts:3: musl failed after 2.0 seconds (not 6.0 seconds), because musl uses timeout and retry intervals inside a bounded overall query window rather than waiting sequentially for timeout × attempts.
Matplotlib dual-panel chart comparing DNS time-to-fail across seven container runtimes (5s to 120s) and musl versus glibc --dns-opt timeout curves
Matplotlib benchmark of container DNS failure durations against --dns 192.0.2.1 on Docker Engine 27.3.1: comparing default time-to-fail across seven tools (left) and measured getaddrinfo timeout curves in musl (python:3.13-alpine) versus glibc (python:3.13-slim) across --dns-opt timeout and attempts settings (right).

Four checks to find where it breaks

Run these four checks in order to separate a broken IP route, a bad container /etc/resolv.conf, a blocked outbound UDP port 53, and a broken WSL distro resolver:

Step 1: Does plain IP traffic get out?

docker run --rm alpine:3.20 ping -c 2 1.1.1.1

If ping 1.1.1.1 fails with 100% packet loss or Network is unreachable, the container cannot route IPv4 packets to the internet at all; fix container routing or VPN split-tunnel rules before debugging DNS.

Step 2: Read the container's /etc/resolv.conf

docker run --rm alpine:3.20 cat /etc/resolv.conf
  • nameserver 192.168.65.7: Normal on Official Docker Desktop's default bridge network.
  • nameserver 127.0.0.11: Normal on a user-defined or Docker Compose network; look at the # ExtServers: [...] comment line to see which upstream DNS servers Docker is actually forwarding external queries to.
  • nameserver 8.8.8.8 (when you didn't configure it): Docker stripped a loopback address such as 127.0.0.53 from the host's /etc/resolv.conf and fell back to Google DNS, which fails if your corporate network blocks external UDP port 53.

Step 3: Ask a DNS server directly

docker run --rm alpine:3.20 nslookup deb.debian.org 1.1.1.1

Passing 1.1.1.1 as the second argument tells nslookup to ignore /etc/resolv.conf and query 1.1.1.1:53 directly. If this succeeds while a plain nslookup deb.debian.org fails, outbound UDP port 53 works and you only need to configure a working nameserver in Solution 1 or Solution 2:

Four-step container DNS diagnostic triage workflow and /etc/resolv.conf nameserver origin decoder card
Executing the four-step container DNS triage workflow on Docker Engine 27.3.1: verifying Layer-3 IP routing (ping -c 2 1.1.1.1), decoding /etc/resolv.conf nameserver origins, and proving with nslookup google.com 1.1.1.1 that outbound UDP port 53 works even when the container's default resolver is dead.

Step 4 (Docker Engine in a distro): check the distro itself

If you run Docker Engine installed directly inside a WSL 2 Linux distribution (not Docker Desktop), run the same two checks inside the WSL shell itself:

cat /etc/resolv.conf
nslookup google.com

With WSL DNS tunneling enabled on Windows 11 (the default in current WSL 2 releases), the distro's /etc/resolv.conf normally shows nameserver 10.255.255.254. If nslookup google.com fails inside the WSL distribution too, fix WSL's own DNS first using Solution 3 or Solution 4 below; if the WSL distribution resolves names cleanly while containers fail, configure Docker's daemon DNS in Solution 2.

Fixes, from one container up to all of WSL

Solution 1: A reachable DNS server per container or Compose service (tested)

Passing explicit DNS servers on the container or Compose service works on both Official Docker Desktop and Docker Engine inside a WSL distribution, and it does not require restarting the Docker daemon.

Fix 1.1: docker run flags

docker run --rm \
  --dns=1.1.1.1 \
  --dns=8.8.8.8 \
  --dns-opt="ndots:1" \
  alpine:3.20 nslookup deb.debian.org

Fix 1.2: Docker Compose dns and dns_opt

services:
  web:
    image: alpine:3.20
    dns:
      - 1.1.1.1
      - 8.8.8.8
    dns_opt:
      - ndots:1
      - timeout:2
      - attempts:3

Compose puts services on its own user-defined network, so /etc/resolv.conf inside the container keeps nameserver 127.0.0.11 for internal service discovery while listing your configured servers under # ExtServers:

Docker Compose /etc/resolv.conf verification showing nameserver 127.0.0.11, options ndots:1 timeout:2 attempts:3, and # ExtServers: [1.1.1.1 8.8.8.8]
Rendered from the Compose verification run: /etc/resolv.conf inside the web service retains nameserver 127.0.0.11 while applying options ndots:1 timeout:2 attempts:3 and # ExtServers: [1.1.1.1 8.8.8.8], whereas the broken service configured with dns: [192.0.2.1] times out against 127.0.0.11:53 and exits with code 1.
# Generated by Docker Engine.
# This file can be edited; Docker Engine will not make further changes once it
# has been modified.

nameserver 127.0.0.11
options ndots:1 timeout:2 attempts:3

# Based on host file: '/etc/resolv.conf' (internal resolver)
# ExtServers: [1.1.1.1 8.8.8.8]
# Overrides: [nameservers options]
# Option ndots from: override

On a corporate network or VPN: If your firewall blocks public DNS servers (1.1.1.1, 8.8.8.8) or your container needs to resolve internal company hostnames (*.corp.internal), replace 1.1.1.1 and 8.8.8.8 with your organization's internal DNS server IPs (which you can find from PowerShell with ipconfig.exe /all).

A RUN edit of /etc/resolv.conf is gone at run time

As shown in Case C of our first test run, adding RUN echo "options single-request-reopen" >> /etc/resolv.conf or RUN echo "nameserver 1.1.1.1" > /etc/resolv.conf inside a Dockerfile only affects that single RUN instruction during docker build. When you later start a container from the image, Docker mounts a fresh /etc/resolv.conf into the container and overwrites your changes. Always pass --dns / --dns-opt at run time or set dns: / dns_opt: in docker-compose.yml:

Live n8n 1.76.1 workflow editor on port 5678 executing an outbound HTTP Request on gfl-dnsnet with Compose dns [1.1.1.1, 8.8.8.8] and dns_opt [ndots:1, timeout:2, attempts:3]
Live verification in n8n 1.76.1 (:5678) running on user-defined network gfl-dnsnet: unlike Dockerfile RUN echo edits that disappear at container start, Compose dns: [1.1.1.1, 8.8.8.8] and dns_opt: [ndots:1, timeout:2, attempts:3] persist in /etc/resolv.conf and allow outbound HTTP Request nodes to resolve external and internal domains in 14 ms without EAI_AGAIN timeouts.

Solution 2: Default DNS servers in /etc/docker/daemon.json (Docker Engine inside a distro)

If you run Docker Engine directly inside a WSL 2 Linux distribution, setting "dns" in /etc/docker/daemon.json configures default resolvers for every container and every docker build step on that daemon whenever per-container --dns flags are not provided. (If you use Docker Desktop, edit the equivalent JSON under Docker Desktop Settings → Docker Engine instead of inside a WSL distro.)

Step 2.1: Edit /etc/docker/daemon.json

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<'EOF'
{
  "dns": ["1.1.1.1", "8.8.8.8"],
  "dns-opts": ["ndots:1", "timeout:2", "attempts:3"]
}
EOF

Step 2.2: Check the JSON before restarting

A trailing comma or syntax error in /etc/docker/daemon.json prevents dockerd from starting. Validate the file with Python's built-in JSON parser first:

python3 -m json.tool /etc/docker/daemon.json > /dev/null && echo "JSON Valid"

Step 2.3: Restart the Docker daemon

# On WSL distros with systemd enabled:
sudo systemctl restart docker

# On WSL distros using SysVinit / service scripts:
sudo service docker restart
Production /etc/docker/daemon.json and docker-compose.yml DNS configuration templates validated with python3 -m json.tool and docker compose config
Production DNS configuration templates validated with python3 -m json.tool and docker compose config: setting daemon-wide default resolvers in /etc/docker/daemon.json for Docker Engine inside a WSL distribution (left) versus per-service dns and dns_opt overrides in docker-compose.yml (right).

Solution 3: WSL DNS tunneling and mirrored networking (from Microsoft's docs)

When DNS fails inside the WSL 2 distribution itself, most commonly after connecting a corporate VPN or on enterprise Windows 11 machines with strict host firewall policies, Microsoft recommends enabling WSL DNS tunneling (dnsTunneling=true) and, on Windows 11 22H2+ (build 22621+), mirrored mode networking (networkingMode=mirrored). Instead of sending UDP port 53 packets over the Hyper-V NAT virtual switch, DNS tunneling resolves queries directly through the Windows host via virtualization features and sets the distro's /etc/resolv.conf to nameserver 10.255.255.254.

Keep one important boundary from Microsoft's WSL networking documentation in mind: Docker Desktop containers bypass WSL DNS tunneling (they use 192.168.65.7 inside Docker Desktop's environment). Solution 3 therefore fixes DNS for the WSL distro and for Docker Engine running inside a WSL distro, whereas Docker Desktop containers still need Solution 1 if 192.168.65.7 cannot reach an upstream resolver.

Step 3.1: Check your WSL version

wsl.exe --version
wsl.exe --update

Step 3.2: Configure %USERPROFILE%\.wslconfig

.wslconfig Key under [wsl2] Default Value What It Does (from Microsoft's WSL Config Docs)
networkingMode NAT Set to mirrored on Windows 11 22H2+ to mirror host network interfaces into WSL and improve VPN compatibility.
dnsTunneling true Routes WSL DNS requests directly to the Windows host without UDP packets over the NAT virtual switch.
dnsTunnelingIpAddress 10.255.255.254 Specifies the IP address written as the nameserver in the WSL distro's /etc/resolv.conf when DNS tunneling is active.
autoProxy true Enforces Windows HTTP proxy information inside the WSL distribution.
firewall true Applies Windows Firewall rules and Hyper-V firewall rules to WSL network traffic.
Split architectural comparison of legacy WSL 2 NAT firewall/VPN DNS black-hole versus Windows 11 .wslconfig dnsTunneling=true and /etc/wsl.conf
Comparing WSL 2 DNS routing paths on Windows 11: legacy NAT mode forwards UDP port 53 packets to the Hyper-V virtual switch where strict firewall policies (AllowLocalFirewallRules: False) or VPN routes can block them, whereas dnsTunneling=true in .wslconfig proxies distro queries through 10.255.255.254 directly to the Windows host resolver.

If you stay on networkingMode=NAT without DNS tunneling: Run Get-NetFirewallProfile -PolicyStore ActiveStore in an elevated PowerShell window and check AllowLocalFirewallRules and AllowInboundRules. If either setting is False, Windows Group Policy is blocking the host networking service firewall rule that NAT mode needs to relay DNS queries from WSL.

Step 3.3: Restart WSL

After saving %USERPROFILE%\.wslconfig, shut down WSL from PowerShell and wait at least 8 seconds before reopening your Linux terminal so the utility VM restarts cleanly:

wsl.exe --shutdown

Solution 4: Write the distro's /etc/resolv.conf yourself (Microsoft's VPN workaround)

If an older WSL build or a legacy VPN client still prevents automatic DNS resolution inside a WSL distribution, Microsoft's troubleshooting guide documents a manual fallback: stop WSL from auto-generating /etc/resolv.conf and write your Windows host's active DNS servers into the file yourself.

  1. Step 4.1: Find the DNS servers Windows is currently using: In PowerShell, run ipconfig.exe /all and copy the IPv4 addresses listed under DNS Servers for your active VPN or network adapter.
  2. Step 4.2: Tell WSL not to overwrite /etc/resolv.conf: Inside the WSL distro, set generateResolvConf = false in /etc/wsl.conf:
    [network]
    generateResolvConf = false
  3. Step 4.3: Replace the symlink with a regular file: After running wsl.exe --shutdown from PowerShell, remove the old symlink in WSL and write the DNS servers you copied:
    sudo unlink /etc/resolv.conf
    sudo tee /etc/resolv.conf <<'EOF'
    nameserver 1.1.1.1
    nameserver 8.8.8.8
    EOF
  4. Step 4.4: Watch out for two side effects: Setting generateResolvConf = false disables WSL DNS tunneling for that distribution, and when you disconnect from the VPN or move to another network, you must update /etc/resolv.conf manually (or remove generateResolvConf = false, delete /etc/resolv.conf, and run wsl.exe --shutdown so WSL manages it again):
Matplotlib benchmark chart comparing single DNS lookup latency (10,012ms vs 14.2ms) and Debian apt-get curl installation duration (120s vs 2.8s)
Empirical latency and package-install benchmark on Docker Engine 27.3.1: replacing an unreachable resolver (10,012 ms glibc timeout and 120.0 s apt-get update stall) with --dns 1.1.1.1 or Compose ExtServers [1.1.1.1 8.8.8.8] reduces getaddrinfo resolution to 14.2 ms and completes Debian curl installation in 2.8 seconds.

Which fix fits your setup

Use the comparison table below to pick the narrowest fix that matches your Docker setup (Official Docker Desktop vs Docker Engine inside a WSL 2 distribution) and network environment:

Fix Applies To Scope Tested Here? Watch Out For
Solution 1: --dns / Compose dns: & dns_opt: Docker Desktop & Docker Engine in a WSL distro (including Alpine musl) One container or Compose service at run time Yes (2025-01-26) A RUN echo >> /etc/resolv.conf in a Dockerfile is overwritten at container start; docker build has no --dns flag.
Solution 2: /etc/docker/daemon.json "dns" Docker Engine inside a WSL distro (or Docker Desktop Settings → Docker Engine) All containers & builds on that daemon Config validated (json.tool) Requires sudo systemctl restart docker; public IPs (1.1.1.1) fail if your VPN only allows internal corporate DNS.
Solution 3: .wslconfig dnsTunneling=true / mirrored WSL 2 distributions on Windows 11 22H2+ All WSL 2 distros on the Windows host From Microsoft's WSL docs Docker Desktop containers use 192.168.65.7 and bypass WSL DNS tunneling; pair with Solution 1 for Desktop containers.
Solution 4: Manual /etc/resolv.conf (generateResolvConf = false) A single WSL 2 distribution on legacy VPNs That WSL distro (and containers copying its file) From Microsoft's WSL docs Opting out of auto-generation disables WSL DNS tunneling and must be updated or reverted when switching networks.
Four-solution WSL 2 and Docker DNS architectural decision matrix comparing --dns/Compose, daemon.json, .wslconfig dnsTunneling, and manual /etc/resolv.conf
Decision matrix across all four WSL 2 and Docker DNS remediation layers: matching container runtime flags (Solution 1), daemon-wide defaults (Solution 2), Windows 11 DNS tunneling (Solution 3), and static distro resolv.conf overrides (Solution 4) to your exact Docker backend and VPN topology.

What I didn't test

  • Docker Engine installed directly inside a WSL distro, live VPN client intercepts, and Windows Firewall Group Policy blocks: My empirical runs on 2025-01-24 through 2025-01-26 were executed on Official Docker Desktop for Windows 11 (WSL 2 backend, Engine 27.3.1) using --dns 192.0.2.1 to simulate an unreachable upstream resolver. The behavior of 127.0.0.53 loopback stripping, /etc/docker/daemon.json inside a distro, dnsTunneling=true (10.255.255.254), and generateResolvConf = false comes directly from Docker's and Microsoft's official documentation.
  • Hardware firewall packet drops that require single-request or single-request-reopen: I verified that passing --dns-opt writes the option into /etc/resolv.conf at container run time and measured how musl and glibc handle timeout and attempts against an unreachable server, but I did not test against a hardware NAT device that drops parallel IPv4 A and IPv6 AAAA packets on the same socket.
  • docker build with a dead daemon resolver: I ran the apt-get update && apt-get install -y curl experiments with docker run --dns ... rather than inside a docker build step.
Four-command production container DNS healthcheck, /etc/resolv.conf # ExtServers audit, and multi-runtime getaddrinfo verification card
Four-command post-deployment DNS verification checklist for Docker on WSL 2: auditing /etc/resolv.conf and # ExtServers on Compose networks, verifying 127.0.0.11 external forwarding with nslookup, testing Python socket.getaddrinfo latency, and enforcing a DNS-aware container healthcheck.

Last reviewed: 2025-01-26. Measured between 2025-01-24 and 2025-01-26 (KST) on Docker Desktop for Windows 11 (WSL 2 backend, Docker Engine 27.3.1, build ce12230, Linux kernel 6.6.87.2-microsoft-standard-WSL2) using alpine:3.19, alpine:3.20, python:3.13-slim, python:3.13-alpine, node:22-alpine, debian:bookworm-slim, and ubuntu:24.04. WSL 2 DNS tunneling (10.255.255.254), .wslconfig settings, and 127.0.0.53 fallback behaviors are referenced from Microsoft's WSL Networking documentation and Docker's Container Networking documentation.

100% Client-Side Utilities · Printable A4 Runbook

Run Prefilled Sizing Math & Download the 1-Page Runbook

Generate hardened Compose service definitions with explicit healthchecks and verify Thunderbolt dock display bandwidth.

Paired Prefilled Calculators & Vector PDF Checklist

Yun Sanghun (M. Yun) · Linux, Docker & AI Infrastructure Engineer