Query docker embedded dns from host

Does anyone know a way to query the built-in DNS server that uses the docker daemon. I am experimenting with packages, and it would be useful if I could replace the docker ip addresses with container names.

The only way I can do this now is to create a DNS server in a container that can be configured as a DNS server for the host to ensure that the container names can be resolved by the host. Hope this makes sense?

Is this the only way or are there other options?

The containers I'm trying to query were created using docker-compose.

+8
source share
3 answers

Consul

I like to use the Hashicorp Consul for this. It can run as an installed client or container and provides a DNS interface that you can request from an external Docker device. It also has features such as service discovery and monitoring, and is open source.

https://www.consul.io/docs/agent/dns.html

One of the main query interfaces for the Consul is DNS. The DNS interface allows applications to use service discovery without integration with a highly touchable Consul.

For example, instead of making HTTP API requests to Consul, the host can use the DNS server directly through a name lookup, such as "redis.service.east-aws.consul". This query automatically searches for nodes that provide redis service, are located in the east-aws data center, and do not have any health checks. It's simple!

This may be redundant for what you are looking for, but should do the job.

Dnsmasq

A simpler alternative would be DNSMasq. I am not so familiar with this, but for a really small scale this will let your DNS host know about the launch of containers.

http://www.thekelleys.org.uk/dnsmasq/doc.html

https://hub.docker.com/r/andyshinn/dnsmasq/

+2
source

You can use socat for the cirocosta/expose-edns Docker network converter in 127.0.0.11:53 as a cirocosta/expose-edns image of cirocosta/expose-edns , which is essentially:

 socat UDP4-RECVFROM:53,fork,bind="0.0.0.0" UDP4-SENDTO:127.0.0.11:53 

Then use it like:

 host container_name_to_resolve 'docker inspect --format \ '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' socat_container_name' 

Also note that the socat container must be on the same Docker network as the destination containers.

0
source

Another way would be to use docker-dns . This is a Docker container that provides a DNS server that resolves Docker containers.

Running it is as easy as

 docker run -d --name dns -v /var/run/docker.sock:/docker.sock phensley/docker-dns 
0
source