Linux

Ubuntu 22.04 laptop: Docker containers lose DNS after suspend/resume due to systemd-resolved stub resolver race with NetworkManager

Environment

Environment

Dell XPS 13 running Ubuntu 22.04, Docker 24.0 using bridge network and containers using host's /etc/resolv.conf which points to 127.0.0.53 (systemd-resolved). NetworkManager manages Wi‑Fi and switches DNS on resume.

Symptoms

Symptoms

After resume from suspend, containers fail DNS lookups (curl, apt) while host name resolution works. Restarting Docker daemon temporarily restores DNS inside containers. Host resolv.conf points to systemd stub but systemd-resolved shows correct upstream servers.

Observations

Observations

Inside containers, /etc/resolv.conf remains as 127.0.0.53; containers' /etc/nsswitch.conf uses hosts: files dns. strace of container resolver shows repeated ECONNREFUSED to 127.0.0.53 until Docker daemon restart. NetworkManager logs show DNS is reconfigured on resume with a brief gap while systemd-resolved listens on stub socket.

Already attempted

Already attempted

Tried 'systemctl restart systemd-resolved' without container DNS repair. Tried recreating containers; problem persists until Docker restart. Edited Docker daemon to set 'dns' to upstream IPs — worked but not ideal for roaming laptops.

Question

Question

How can I make container DNS survive suspend/resume reliably while keeping host systemd-resolved stub and NetworkManager-managed DNS on a roaming laptop?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
Swoop Answer
user
Posted 1mo ago • 0 confirmations

Don’t rely on the host loopback stub inside bridged containers—systemd-resolved briefly rebinds on resume and container queries to 127.0.0.53 get refused. Easiest safe fix: add real upstream DNS to Docker daemon (daemon.json "dns": ["1.1.1.1"]) and restart Docker; containers keep DNS across suspend/resume. Cleaner: run host dnsmasq bound to the host bridge IP and configure Docker to use that IP so containers have a stable resolver. Both are reversible; test by suspending/resuming and verifying 'docker run --rm busybox nslookup google.com'.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Race where systemd-resolved's stub listener is briefly unavailable after resume and containers' DNS queries to 127.0.0.53 are refused until Docker restart 90%
Docker bridge network isolates container network namespace so host-local stub address isn't consistently reachable through normal container networking after DNS rebind events 65%
NetworkManager reconfiguration replaces resolv.conf symlink in a way containers don't observe, leaving stale references 40%

Summary

Containers relying on host stub resolver (127.0.0.53) will hit an ephemeral socket race: on resume NetworkManager reconfigures DNS and systemd-resolved may briefly unbind/rebind its stub listener; meanwhile containers' libc resolvers keep referring to the stub address but the Docker bridge isolates container networking from host namespace, causing packets to 127.0.0.53 to be routed incorrectly until Docker restarts or host rebinds socket. Workarounds: have Docker inject real upstream DNS into containers via daemon.json dns entries or use dnsmasq bound to non-loopback address; alternatively configure systemd-resolved to provide a stable local IP (127.0.0.53 is valid only in host network namespace) by exposing a nameserver on an interface address reachable from containers.

Suggested Fixes

Diagnostic step 1
Short-term: configure Docker daemon with fixed upstream DNS entries (e.g., in /etc/docker/daemon.json set "dns": ["1.1.1.1","8.8.8.8"]) and restart Docker; reversible by removing entries.
Diagnostic step 2
Better: run a lightweight DNS forwarder (dnsmasq) on the host bound to the host's bridge IP (not 127.0.0.1), and set Docker daemon 'dns' to that IP so containers use a stable nameserver across resume.
Diagnostic step 3
Alternative: start containers with --network=host where appropriate so they use host stub resolver directly (caveat: network isolation loss).

Continue troubleshooting

Matched from the title, description and tags