Docker containers and dnsmasq on the host

I am using dnsmasq to orchestrate libvirt virtual machines and provide custom hostname resolve rules. To use dnsmasq you normally put "nameserver 127.0.0.1" into your /etc/resolv.conf .

But when docker sees '127.0.0.1' in /etc/resovl.conf it will use Google's public DNS servers inside container. The only way to alter this behavior is specify '--dns x.x.x.x' when running docker daemon or running specific image. Since I wanted to automate this process, to make sure that everything will still work even if IP address of the host will change in future, I added following line into /etc/default/docker file and restart it with "sudo service docker restart":

DOCKER_OPTS="--dns `host \`hostname\` | awk '/^[[:alnum:].-]+ has address/ { print $4 }'`"

What this does - fetches network ip address of the machine. This is what docker run with

$ ps aux | grep docker
root      3599  2.2  0.1 637364 12880 ?        Ssl  22:23   0:00 /usr/bin/docker -d --dns 192.168.122.101

From there your containers should be able to reach internal network resources by specifying their names.