I want to create a docker container for bind instead of running a dns/dhcp virtual server. Basically, I am trying to move into the current decade. As per my last post, setting up docker turned out to be pretty easy. As I need to create a couple of different containers, I wanted to document my experience here in order to replicate it for dhcp and web services.

Docker base image

I wanted to start with the base ubuntu image and then overlay bind on top. In the future, I want to use a docker file to do these steps, but first I want to try it manually to make sure I have the right steps.

Most instructions I found on the internet simply called to publish by the port numbers, but my machine has port 53 bound to dnsmasq on the bridge ip that KVM uses. As such, I had to specify which ip address I wanted port 53 to bind to

docker run -it --name xdns -h xdns --publish 192.168.80.13:53:53/tcp --publish 192.168.80.13:53:53/udp ubuntu

Start installing stuff

Once I had the image up, I simply tried installing bind.

apt-get update
apt-get upgrade -y
DEBIAN_FRONTEND=noninteractive apt-get -y install bind9
/etc/init.d/bind9 start

This seemed way to easy. Quickly testing that it worked showed that it really was that easy.

dig 192.168.80.13 google.com

Next steps

While this technically worked, it didn’t do a whole lot as I didn’t do any of the bind config work. So I went ahead and removed the container I just created and tried again - this time mounting local folders to the config folders that bind uses.

docker rm xdns
mkdir /srv/xnds/etc_bind
mkdir /srv/xnds/var_lib_bind

Next I copied all of my bind configs over to these newly created folders. If you are interested in my whole bind setup, I am pretty sure there is another post on this site that goes into that - dns setup post.

I did have to make one interesting change in my config to make this work - in the my named.conf.options file I had listed localhost and localnets as “internal” networks to respond to. Unfortunately, this didn’t work with this setup - I am assuming the paired down docker image didn’t understand what network it was a part of. Simply adding 192.168.80.0/24 to the internal acl fixed this.

After that, I went ahead and created xdns again, this time with the volumes mapping to my newly created folders.

docker run -it --name xdns -h xdns --publish 192.168.80.13:53:53/tcp --publish 192.168.80.13:53:53/udp --volume /srv/xdns/etc_bind:/etc/bind --volume /srv/xdns/var_lib_bind:/var/lib/bind ubuntu

Once again, I went through my simple setup steps to install bind and start the services.

apt-get update
apt-get upgrade -y
DEBIAN_FRONTEND=noninteractive apt-get -y install bind9
/etc/init.d/bind9 start

Last thoughts

That’s it for today - I still want to setup a dockerfile for this process, but that is a project for a different night…

Credits:

docker-bind Sameersbn has an awesome opensource project for running bind in a docker container. I looked through his dockerfile and shell scripts to understand how this is all glued together - I highly recommend his if you are looking for the easy option to running bind in a container.