Why do my containers lose DNS access after a reboot?
Asked by
late-fee forgiven
I've been running Docker on a Debian Linux server for years with several containers and no major problems. Over the past few months, the containers start normally after a reboot, but they 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 startup-time behavior, and how can I diagnose and fix it?
Answers
Docker determines a containerโs DNS configuration when the container starts; it doesnโt continuously reread the hostโs /etc/resolv.conf. This usually points to a boot-order race where Docker starts before networking, a resolver service, or another tool has finished configuring that file. Check the hostโs resolv.conf and the containerโs /etc/resolv.conf immediately after boot, then compare them after restarting a container. As a workaround, configure stable DNS servers in /etc/docker/daemon.json, for example: {"dns":["1.1.1.1"]}, and restart Docker.
Reply to this answer
Also investigate boot-time firewall changes. Docker creates forwarding and NAT rules when it starts, but a firewall service loaded afterward may flush or override those rules. Compare the firewall and Docker rules immediately after boot with the rules after the containers begin working, and check system logs for firewall reloads or failed network initialization.
Reply to this answer
On systems using cloud-init or automated network configuration, resolv.conf may not be ready when Docker launches. Review the boot sequence and journal logs for Docker, the network manager, cloud-init, and the resolver service. Fixing the service ordering or disabling the component that keeps rewriting resolv.conf is better than relying on manually restarting containers.
Reply to this answer
If you use Tailscale or another network manager, check whether it replaces /etc/resolv.conf during startup. A resolver such as 100.100.100.100 may work for the host but not from Docker containers. Look at the file before and after the network service starts, and inspect the service logs for changes. Configuring a reliable fallback nameserver or adjusting the resolver integration can prevent the race.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions