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 add
You can use socat
to expose the Docker network's resolver at 127.0.0.11:53
like cirocosta/expose-edns image does, 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 in the same Docker network as target containers.
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:
docker run -d --name docker-dns -v /var/run/docker.sock:/docker.sock \
phensley/docker-dns --domain docker --no-recursion
Then inspect its IP address with:
docker inspect --format \
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' docker-dns
And put it into /etc/NetworkManager/dnsmasq.d/docker.conf
like:
server=/docker/1.2.3.4
After systemctl restart NetworkManager
you should be able to address your Docker containers from host like ping CONTAINER_NAME.docker
which is quite handy for dockerised development environments.