Linux

Ubuntu 22.04 laptop: Docker containers lose DNS resolution after suspend/resume (systemd-resolved stub resolver conflict)

Environment

Environment

Ubuntu 22.04 Desktop on a Lenovo X1 Carbon; Docker Engine 24.x using default bridge network; host uses systemd-resolved with DNS stub listener on 127.0.0.53 and NetworkManager manages network changes (Wi‑Fi to VPN).

Symptoms

Symptoms

After resuming from suspend, running containers cannot resolve DNS names (e.g., apt update inside container returns 'Temporary failure in name resolution'), while host DNS works. Restarting Docker daemon or recreating containers fixes DNS until the next suspend/resume.

Observations

Observations

On host: 'systemd-resolve --status' shows DNS servers changed after resume (VPN activated) and /etc/resolv.conf points to 127.0.0.53. Containers' /etc/resolv.conf files still list the previous DNS IPs or a stale stub address and do not update automatically. 'docker inspect' for container shows 'DNS' field empty (Docker copies host resolv.conf at container start). After resume, NetworkManager updates host stub resolver but Docker's embedded DNS inside container did not get refreshed. No DNS packets seen from containers to the new upstream server (tcpdump on docker0 shows no traffic).

Already attempted

Already attempted

Restarting Docker service restores container DNS (Docker rebuilds /etc/resolv.conf). Attempted to run containers with 'network=host' as a test — host name resolution worked inside host-networked containers after resume. Tried setting 'dns: 1.1.1.1' in docker-compose as a workaround — that avoids the issue but is not ideal for privacy/VPN contexts.

Question

Question

Why do containers retain stale DNS after host network changes on resume, and how can I make Docker pick up updated systemd-resolved DNS without restarting containers or the Docker daemon each time?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Docker copies host resolv.conf at container creation and does not dynamically update container DNS when host DNS changes on resume. 95%
systemd-resolved stub resolver semantics (127.0.0.53) plus NetworkManager changing upstreams confuses container networking if containers attempt to bypass the stub. 60%
VPN client or NetworkManager uses per-connection DNS namespaces that are not visible to Docker default bridge-created containers. 40%

Summary

Docker captures /etc/resolv.conf from the host when the container is created. On systems using systemd-resolved with a changing upstream (VPNs, Wi‑Fi), the host's /etc/resolv.conf often points to the local stub (127.0.0.53), but NetworkManager or systemd updates upstream servers after resume. Docker-internal DNS doesn't dynamically reconfigure existing containers; the engine or container must be recreated to pick up new DNS. This is expected behavior. The observed difference between containers and host (host resolves, containers don't) confirms stale resolv.conf inside containers. Workarounds include running Docker with a stable DNS server, using a local DNS forwarder bound to a stable address accessible from containers, or using Docker's --dns option when starting containers. System-level integration approaches exist but are not automatic.

Suggested Fixes

Diagnostic step 1
Confirm root cause: inspect /etc/resolv.conf inside an affected container and compare with host's /etc/resolv.conf after resume to see the mismatch.
Diagnostic step 2
Short-term workarounds: start containers with a fixed DNS server (--dns 1.1.1.1) or configure docker daemon's /etc/docker/daemon.json with a default DNS to avoid dependence on host resolver changes.
Diagnostic step 3
Better integration: run a lightweight DNS forwarder (dnsmasq or systemd-resolved on a non-loopback address) on the host bound to a stable address accessible by containers (e.g., 172.17.0.1) and point containers' DNS to that; update Docker daemon configuration to use that address as default DNS.

Continue troubleshooting

Matched from the title, description and tags