Docker's --dns stops mattering once a container joins a second network

The DRA containers are created on one network, attached to a partner network afterwards, and started last — by which point the resolver config Docker wrote is the wrong one.

Containers

How the container is actually started

The deployment is three Docker commands in one Ansible task, in this order. docker create (with --dns for both site resolvers), then docker network connect --ip=… for the partner network, then docker start. The resolver configuration is fixed at create time (one docker create, two --dns flags). The second interface arrives after it.

Inside the container, resolution failed for the internal services the DRA needs (etcd, the message broker, the HSS by name). From the commit that closed it:

As the standard way of injecting DNS into a container with the --dns option is not working when the container connects to multiple networks.

One sentence — and enough to act on. The fix moves the nameservers out of a Docker flag and into the container's own startup.

Render resolv.conf at process start

The values became two environment variables on the Ansible side (DNS_SERVER_1 and DNS_SERVER_2, from group_vars: 10.255.0.200 in prod, 10.255.0.202 in dev). The container then writes its own /etc/resolv.conf from a template:

search <corporate domain>
nameserver 127.0.0.11
nameserver {{ .DNS_SERVER_1 }}
nameserver {{ .DNS_SERVER_2 }}
options edns0 timeout:1 attempts:2 rotate no-inet6 ndots:0

envtpl renders it from the s6 run script for freeDiameter (services.d/freeDiameter/run). So it happens when the service starts, after every network is attached, every time the container comes up.

127.0.0.11 stays first on purpose. That is Docker's embedded resolver, and it is the only thing that resolves container names on the user-defined networks; the two site resolvers behind it answer everything else.

The options line is the part worth reading twice. ndots:0 stops the search domain being pasted onto an already-qualified peer name. no-inet6 keeps freeDiameter off AAAA lookups nobody here serves. timeout:1 attempts:2 rotate caps a dead resolver at two seconds (the default is five seconds per server, tried in order).

The first version shipped quoted

The template went in at 11:28 with the substitutions quoted:

nameserver "{{ .DNS_SERVER_1 }}"
nameserver "{{ .DNS_SERVER_2 }}"

resolv.conf has no quoting (it is read token by token, never shell-style). The resolver reads the token after nameserver as an address, and a quoted string will never parse as one. Both lines are dropped in silence; nothing logs it. The container is left with 127.0.0.11 alone — exactly the state the change existed to get out of, so it read as a fix that had done nothing.

The unquoted template landed at 21:21 the same day, under the same ticket (four commits in all: template, banner, unquote, merge).

The banner was the other half

/etc/resolv.conf is the first file anyone opens when DNS is wrong on a host. This one is rewritten on every restart, so the run script emits a header above the rendered content:

# DO NOT EDIT THIS FILE
# This file is re-generated from /etc/resolv.conf.tpl at container startup
# If there is a change in name server change it in the Ansible repository

That shape outlived the DNS fix. Every generated file in the container now carries the same banner (freeDiameter.conf, fixups_config.json), each naming the template it came from. The STP image reuses the resolv.conf block verbatim. Four files to render is four chances to lose an hour to a local edit that a restart quietly discards.