At each depot a small Linux server runs our print agent, a container that fetches label jobs from a service whose hostname lives in our private DNS zone, and sends carrier requests to public APIs. The agent is started with a plain docker run, so it sits on Docker's default bridge network.
In August we rolled out a new server build. To cut DNS traffic over the VPN to head office, it installs dnsmasq as a local cache and points /etc/resolv.conf at it, with a single line: nameserver 127.0.0.1. Everything on the host resolved names exactly as before. On the first three new servers, the print agent could not resolve one internal name, while every call it made to the carriers worked.
A container on the default bridge does not use the host's resolver. Docker gives it a copy of the host's resolv.conf. Inside the container 127.0.0.1 is the container itself, so Docker filters loopback nameservers out of the copy. If nothing is left after that, it does not fail. It writes in Google's public resolvers, 8.8.8.8 and 8.8.4.4. Our depot internet lines allowed outbound DNS, so the agent asked Google, Google answered every public name correctly, and every name in our private zone came back as not found.
Docker has one exception: on a host running systemd-resolved, it skips the 127.0.0.53 stub and copies the real upstream servers from /run/systemd/resolve/resolv.conf. A local dnsmasq gets no such treatment.
The old build had listed the head office DNS servers in resolv.conf directly, so the copy had always been right, and none of us had ever looked at it.
The dns setting in daemon.json now lists the head office servers, so every container created on these hosts gets them whatever the host's own file says. The server build's test starts a throwaway container and resolves an internal name from inside it, because resolving it from the host had proved nothing. The depot firewalls now allow DNS only to our own servers, so a container that goes looking for Google fails at once and says so.
A container inherits its host's settings only as far as they still make sense from inside it. Where they do not, Docker substitutes something, and the substitute can look as if it works.
– Sergey Shinder
