Ubuntu 22.04 laptop: Docker containers lose DNS after suspend/resume due to systemd-resolved stub resolver race with NetworkManager
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
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
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
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
How can I make container DNS survive suspend/resume reliably while keeping host systemd-resolved stub and NetworkManager-managed DNS on a roaming laptop?
Verified community troubleshooting
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'.
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Linux61% match
Ubuntu 22.04 laptop: Docker containers lose DNS resolution after suspend/resume (systemd-resolved stub resolver conflict)
Open0 answers - Linux57% match
Ubuntu 22.04: Docker containers intermittently lose DNS after host switches to systemd-resolved stub resolver during network changes
Solved1 answer - Virtualization54% match
Docker containers lose DNS resolution after laptop resume on Ubuntu 22.04 due to systemd-resolved stub resolver change
Open0 answers - Linux46% match
Docker containers lose DNS after host switched to systemd-resolved stub resolver on Ubuntu 22.04
Solved1 answer - Linux45% match
Docker containers lose DNS resolution after laptop suspend/resume on Ubuntu 22.04
Open0 answers