Skip to content

Warn when no external DNS nameservers are found#49827

Merged
robmry merged 1 commit intomoby:masterfrom
robmry:warn_no_ext_nameservers
Apr 17, 2025
Merged

Warn when no external DNS nameservers are found#49827
robmry merged 1 commit intomoby:masterfrom
robmry:warn_no_ext_nameservers

Conversation

@robmry
Copy link
Copy Markdown
Contributor

@robmry robmry commented Apr 17, 2025

- What I did

Since commit 925b484 ("No fallback nameservers for internal resolver"), if the host's resolv.conf has no nameservers and no servers are supplied via config, the internal resolver will not use Google's DNS - so the container will not be able to resolve external DNS requests.

That can happen when containers are "restart always/unless-stopped" and the docker daemon starts before the host's DNS is configured.

So, highlight the issue (which may not be an error, but probably is).

- How I did it

Include a warning in the container's resolv.conf file.

Also, log a warning - logs currently say "No non-localhost DNS nameservers are left in resolv.conf. Using default external servers". But, that's misleading because it's from an initial resolv.conf setup, before the internal resolver configured without those fallbacks - we'll drop the fallbacks completely once the default bridge has an internal resolver).

- How to verify it

Updated unit test.

With an empty /etc/resolv.conf on the host ...

$ docker run --rm -ti --network b4 busybox cat /etc/resolv.conf
# Generated by Docker Engine.
# This file can be edited; Docker Engine will not make further changes once it
# has been modified.

nameserver 127.0.0.11
options ndots:0

# Based on host file: '/etc/resolv.conf' (internal resolver)
# NO EXTERNAL NAMESERVERS DEFINED
# Overrides: []
# Option ndots from: internal
INFO[2025-04-17T09:49:54.159880089Z] No non-localhost DNS nameservers are left in resolv.conf. Using default external servers
WARN[2025-04-17T09:49:54.161602381Z] DNS resolver has no external nameservers      cid=1ee4ac99aac0bba02692dedbb8168e11f2300f2bba82d6126eb461c8a6c9305a

- Human readable description for the release notes

- Add a warning to a container's `/etc/resolv.conf` when no upstream DNS servers were found.

Since commit 925b484 ("No fallback nameservers for internal
resolver"), if the host's resolv.conf has no nameservers and
no servers are supplied via config, the internal resolver will
not use Google's DNS - so the container will not be able to
resolve external DNS requests.

That can happen when container's are "restart-always" and the
docker daemon starts before the host's DNS is configured.

So, to highlight the issue (which may not be an error, but
probably is), include a warning in the container's resolv.conf
file.

Also, log a warning - logs currently say "No non-localhost DNS
nameservers are left in resolv.conf. Using default external
servers". But, that's misleading because it's from an initial
resolv.conf setup, before the internal resolver configured without
those fallbacks - we'll drop the fallbacks completely once the
default bridge has an internal resolver).

Signed-off-by: Rob Murray <rob.murray@docker.com>
@robmry robmry added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. area/networking Networking impact/changelog area/networking/d/bridge Networking area/networking/dns Networking version/28.0 labels Apr 17, 2025
@robmry robmry added this to the 28.2.0 milestone Apr 17, 2025
@robmry robmry self-assigned this Apr 17, 2025
@robmry robmry marked this pull request as ready for review April 17, 2025 11:15
@vvoland vvoland modified the milestones: 28.2.0, 28.1.1 Apr 17, 2025
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah
Copy link
Copy Markdown
Member

@robmry quick question (could be for a follow-up); would we be able to log a warning when loading the config?

I'm considering dockerd --validate to print a warning;

dockerd --validate
WARNING: yada yada yada
configuration OK

I should also dust-off my PR that prints the external resolvers in docker info, but I wasn't 100% sure at the time if it printed the correct info (for the systemd-resolvd case), but it's been a long time since I looked at it!

@robmry
Copy link
Copy Markdown
Contributor Author

robmry commented Apr 17, 2025

@robmry quick question (could be for a follow-up); would we be able to log a warning when loading the config?

I'm considering dockerd --validate to print a warning;

In normal running, a network-connected Linux host with no external resolvers would be very unusual - it wouldn't be able to resolve DNS requests, so I don't think it would be surprising that its containers wouldn't resolve DNS either (at least, without a --dns option).

That's why the original change didn't worry about that case too much ... but the issue that's been raised seems to be caused by dockerd starting before the host's DNS is configured, and containers that start immediately because they're configured with a "restart" option.

So, by the time dockerd --validate gets run - the issue is very likely to have been resolved for the host, but not for those containers that started early ... I don't think the warning would help (and would most-likely never be seen anyway).

Without containers starting early, no DNS when the daemon starts isn't an issue. If the containers do start early, there will now be warnings in the logs - so I don't think it's worth adding extra warnings during startup either.

I should also dust-off my PR that prints the external resolvers in docker info, but I wasn't 100% sure at the time if it printed the correct info (for the systemd-resolvd case), but it's been a long time since I looked at it!

That could be useful sometimes - but perhaps also misleading, because containers only snapshot the server's state when they start and the daemon-level DNS related options can be overridden per-container. Since you worked on that PR, I think we've dealt with the issues around localhost nameservers - mostly by making DNS lookups from the host's netns when a nameserver address is learnt from the host. (The default bridge network still uses Google's fallback servers in that case but, hopefully, we'll be able to hook it up to the internal resolver again soon - just need to sort out the buildkit issue.)

So, DNS config is per-container not per-daemon - and the config is now visible in comments in the container's /etc/resolv.conf ... perhaps adding DNS info to a running container's inspect output might be worthwhile though?

@robmry robmry merged commit 6573a13 into moby:master Apr 17, 2025
176 checks passed
@robmry robmry deleted the warn_no_ext_nameservers branch May 29, 2025 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/networking/d/bridge Networking area/networking/dns Networking area/networking Networking impact/changelog kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. version/28.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants