Docker allocation cannot resolve *.consul DNS

Apologies if this question has been asked before, I feel like its a very common use case but I couldn’t find an answer.

Currently if I want my Docker containers to be able to resolve *.consul dns (ie myother-app.service.consul) I need to add this 2 parameters in the job -> group -> task-> config:

dns_servers = [
          "${attr.unique.network.ip-address}",
        ]

        dns_search_domains = [
          "consul",
        ]

I do this to each Nomad Job I have. I was wondering that there must be a better way to do this and avoid so much duplication.

Could some one point me in the right direction?

Thanks!

The thing ~ I did:

install dnsmasq, ensure it is listening on 172.17.0.1 (for docker iface) or 0.0.0.0 (but firewalled from public iface) on every nomad client and configure it to also ask consul for dns like:

# /etc/dnsmasq.d/10-consul
server=/consul/127.0.0.1#8600

configure docker to use the gateway as dns server in containers

# /etc/docker/daemon.json
{"dns": ["172.17.0.1"]}
1 Like