Docker containers lose DNS after host switched to systemd-resolved stub resolver on Ubuntu 22.04
Environment
Ubuntu 22.04 server running Docker Engine 20.10 on APT-updated host; containers use default bridge network and rely on Docker-generated /etc/resolv.conf inside container.
Symptoms
Containers intermittently cannot resolve external hostnames after switching the host to systemd-resolved's DNSStubListener=udp (i.e., /etc/resolv.conf points to 127.0.0.53). Host name resolution works normally. Restarting Docker or recreating containers temporarily fixes DNS until resolved is restarted.
Observations
Inspecting a container shows /etc/resolv.conf contains 127.0.0.53 copied from host. From inside containers, queries to 127.0.0.53 fail. Creating containers with explicit DNS in daemon.json (e.g. 8.8.8.8) fixes the containers. Docker daemon.json is empty; NetworkManager is managing network configuration.
Already attempted
Restarted systemd-resolved and Docker in various orders; created /etc/docker/daemon.json with "dns": ["8.8.4.4","8.8.8.8"] then restarted Docker which resolved the issue for newly created containers; did not change host-wide resolver behavior.
Question
How should Docker be configured on a system using systemd-resolved so containers keep working after resolver restarts and the host uses the stub resolver at 127.0.0.53?
Verified community troubleshooting
Docker inherits the host's resolv.conf at container creation; if that file points to the systemd stub (127.0.0.53) containers can't reach it. Fast fixes: (A) Configure Docker to use known public DNS servers by creating /etc/docker/daemon.json with {"dns":["1.1.1.1","8.8.8.8"]} and restart dockerd, or (B) switch systemd-resolved to publish real upstream servers by setting DNSStubListener=no in /etc/systemd/resolved.conf, restart systemd-resolved, then symlink /etc/resolv.conf to /run/systemd/resolve/resolv.conf. Verify with docker run --rm busybox nslookup google.com. Both changes are reversible: remove the daemon.json dns entry or set DNSStubListener=yes and restore the original /etc/resolv.conf symlink.
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Linux71% match
Ubuntu 22.04: Docker containers intermittently lose DNS after host switches to systemd-resolved stub resolver during network changes
Solved1 answer - Linux60% match
Ubuntu 22.04 laptop: Docker containers lose DNS resolution after suspend/resume (systemd-resolved stub resolver conflict)
Open0 answers - Linux59% match
Ubuntu 22.04 laptop: Docker containers lose DNS after suspend/resume due to systemd-resolved stub resolver race with NetworkManager
Open1 answer - Virtualization57% match
Docker containers lose DNS resolution after laptop resume on Ubuntu 22.04 due to systemd-resolved stub resolver change
Open0 answers - Linux36% match
Docker containers lose DNS resolution after laptop suspend/resume on Ubuntu 22.04
Open0 answers