You are here

Docker - a DNS server container (ter)

logoOne drawback of my dockerized DNS server is that I have to rebuild it every time I add a new domain name. Today, I decided to simplify it, in the following way:


FROM ubuntu

RUN apt-get update \
 && apt-get install -y bind9 dnsutils nano \
 && rm -rf /var/lib/apt/lists/*

ADD start /start
RUN chmod 755 /start

EXPOSE 53/udp

CMD ["/start"]

The image is built on the latest ubuntu image, now, instead of using my own ubuntu image. nano editor is added, just in case I need to modify some files from inside the container.

start file:


echo "Starting configuration..."
# Ensure right ownership.
chmod -R 644 /data/bind
chown -R root:bind /data/bind
cp /data/bind/* /etc/bind/

echo "Starting named..."
mkdir -m 0775 -p /var/run/named
chown root:bind /var/run/named
touch /var/log/query.log
chown bind /var/log/query.log
exec /usr/sbin/named -u bind -f

Let's say that zone files are in /var/zonefiles/ directory. Once built with name mydnsserver (for instance), the image has to be run as follows:

docker run --name mydnsserver -v /var/zonefiles:/data/bind -d -p 53:53/udp -p 53:53 mydnsserver

When zone configuration has to be updated, stop the container:

docker stop mydnsserver

Modify concerned zone file, and restart the container:

docker start mydnsserver