Why do Docker containers lose DNS after a reboot?

0
0
Asked By MellowPine42 On

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?

3 Answers

Answered By QuietMarble8 On

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.

Answered By CopperLark7 On

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.

Answered By VelvetOrbit3 On

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.