By configuring your Docker containers to talk to a custom DNS server, you gain more control over how your container look
up other services – database, other microservices, etc.,
It turns out Docker networking isn’t completely straight forward. On Linux you can:
- Run a DNS server locally, either dnsmasq or devdns
- Run your container with
--dns 172.17.0.1, the magic IP where your host machine is located
- Configure dnsmasq from step 1 via
Sadly, none of it was easy. The entire thing probably took me three hours.
Install the DNS server was… confusing. I wouldn’t know how to verify if my DNS queries (via the dig command)
where answered by the DNS server I configured. I discovered I was talking to a [systemd-resolved] instance by
guesswork, which prompted me to finally install
But finally, with
dnsmasq running locally, the Docker containers running on my machine can be affected by my
/etc/hosts, which makes integration testing against other services much easier.