Why do Docker containers lose DNS after a reboot?
Asked by
MellowPine42
I've been running Docker on a Debian Linux server for years with several containers and no problems. Over the past few months, containers start normally after a reboot but cannot reach the internet because their DNS configuration appears to be missing or incorrect. If I restart the containers a few minutes later, everything works again. What could cause this boot-time behavior, and what's the best way to diagnose and fix it?
Answers
If you use Tailscale, check for a race with Debianโs networking services. Tailscale can change the host resolver to its own address, such as 100.100.100.100, after Docker has already started. Compare /etc/resolv.conf before and after Tailscale starts, and make sure the resolver Docker receives is reachable from the containers. A stable fallback resolver may help, but the better fix is to correct the service startup ordering or configure Dockerโs DNS explicitly.
Reply to this answer
Docker typically creates a containerโs DNS configuration when the container starts, so it may capture the hostโs /etc/resolv.conf before the networking stack or another service has finished updating it. Restarting the containers later works because the host resolver is valid by then. Check the hostโs resolver file and Docker/container logs at boot, and consider configuring explicit DNS servers in /etc/docker/daemon.json, such as {"dns":["1.1.1.1"]}, instead of relying on boot timing.
Reply to this answer
Cloud-init or another network-management service can also rewrite /etc/resolv.conf during boot. Check system and service logs around startup, identify which process owns or replaces the file, and disable or reconfigure that behavior if it is not needed. Also verify that Dockerโs bridge and firewall rules are still present after bootโcustom firewall rules loaded later can remove Dockerโs forwarding or masquerading rules and make the problem look like DNS failure.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions