Does anybody know a way to query the embedded dns server that the docker daemon uses. I'm experimenting with packetbeats and it would be useful if I could replace docker ip addresses with the container names.
The only way I can currently think of to achieve this is to create a dns server in a container that can be configured as the dns server for the host to ensure container names can be resolved by the host. Hope that makes sense?
Is this the only way or are there other options ?
The containers I'm trying to query were created using docker-compose.
Another way would be to use docker-dns. It's a docker container that exposes a dns server that resolves the docker containers.
Running it is as simple as
Consul
I like using Hashicorp's Consul for this. It can run as an installed client or container, and provides a DNS Interface that you can query external of Docker. It also has features like service discovery & monitoring, and is open source.
https://www.consul.io/docs/agent/dns.html
It might be overkill for what you're looking for, but should do the job.
DNSMasq
A simpler alternative might be DNSMasq. I'm not as familiar with it, but for a really small scale setting it would allow your host to be DNS aware of running containers.
http://www.thekelleys.org.uk/dnsmasq/doc.html
https://hub.docker.com/r/andyshinn/dnsmasq/
You can use
socat
to expose the Docker network's resolver at127.0.0.11:53
likecirocosta/expose-edns
image does, which is essentially:Then use it like:
Also note that the
socat
container must be in the same Docker network as target containers.Update
To overcome the limitation of the same Docker network,
phensley/docker-dns
can be used (which uses Docker API). On an OS with NetworkManager and Dnsmasq enabled (otherwise can be enabled like described in this answer) you can run:Then inspect its IP address with:
And put it into
/etc/NetworkManager/dnsmasq.d/docker.conf
like:After
systemctl restart NetworkManager
you should be able to address your Docker containers from host likeping CONTAINER_NAME.docker
which is quite handy for dockerised development environments.