Linux

Docker containers lose DNS resolution after laptop suspend/resume on Ubuntu 22.04

feliciafix
1mo ago
Environment

Environment

Ubuntu 22.04 LTS desktop, kernel 5.15.0-56-generic, Docker Engine 20.10.12 from Docker CE repo, NetworkManager 1.36, systemd-resolved as stub resolver (127.0.0.53), containers started via docker-compose v1.29.

Symptoms

Symptoms

Containers that previously resolved external hostnames stop resolving DNS after laptop resumes from suspend. Domain lookups inside containers return 'temporary failure in name resolution' while host DNS (host nslookup) works normally.

Observations

Observations

After resume NetworkManager restarts and /etc/resolv.conf is rewritten to the systemd stub. Existing running containers keep the pre-resume /etc/resolv.conf contents copied at creation time. Restarting docker.service or restarting containers restores resolution. New containers created after resume have correct resolv.conf.

Already attempted

Already attempted

Restarted NetworkManager (no change while containers running), recreated an affected container (works), rebooted host (works but inconvenient), added explicit DNS in docker-compose (temporary fix), attempted to bind-mount host /run/systemd/resolve/resolv.conf into container (breaks other services).

Question

Question

Why do containers lose DNS after resume and how can I make DNS stable across suspend/resume without restarting every container? Prefer minimally disruptive solutions for multi-container dev stacks.

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 /etc/resolv.conf into containers at creation; host rewrite on resume leaves running containers with stale DNS 95%
systemd-resolved stub listener and Container loopback mismatch (127.0.0.53 inside host is not reachable from container loopback) 70%
NetworkManager triggers a resolv.conf change that introduces transient invalid nameserver entries until DNS service fully restarts 40%

Summary

Docker copies /etc/resolv.conf from the host into container filesystem at container start and does not update it when the host's resolver changes. On Ubuntu 22.04 systemd-resolved manages DNS via a local stub at 127.0.0.53 and NetworkManager rewrites /etc/resolv.conf on resume, so running containers keep stale resolver entries. Workarounds include: give containers a stable resolver (configure docker daemon dns entries), restart affected containers on resume, or change host resolver configuration so /etc/resolv.conf points to a stable upstream address.

Suggested Fixes

Diagnostic step 1
Confirm issue: run cat /etc/resolv.conf on host and inside an affected container; compare nameserver lines pre/post-resume.
Diagnostic step 2
Quick fix: restart only affected containers: docker-compose restart <service> or docker restart <container>. Verify DNS works with dig or ping inside container.
Diagnostic step 3
Daemon-level fix: set a stable upstream in /etc/docker/daemon.json (e.g. {"dns": ["1.1.1.1", "8.8.8.8"]}) and restart docker.service. This forces containers to use those DNS servers regardless of host resolv.conf.

Continue troubleshooting

Matched from the title, description and tags