How to Setup DNS Server with Docker Container

February 2, 2017 | By in LINUX HOWTO
| Reply More

A Dockerfile is used to create a Docker container image, this will be used to created the DNS Server. An easy way to setup a basic DNS server with Docker is to use the BIND DNS server bundled with the Webmin interface. In this article we cover how to implement DNS server using docker container.

BIND is an open source software that implements the Domain Name System (DNS) protocols for the Internet. It is a reference implementation of those protocols, but it is also production-grade software, suitable for use in high-volume and high-reliability applications.

Automated builds of the image are readily available on Dockerhub and is the recommended method of installation

docker pull sameersbn/bind:9.9.5-20170129

Alternatively you can build the image yourself.

docker build -t sameersbn/bind github.com/sameersbn/docker-bind

To start a BIND DNS server you execute:

docker run --name bind -d --restart=always \ --publish 53:53/tcp --publish 53:53/udp --publish 10000:10000/tcp \ --volume /srv/docker/bind:/data \ sameersbn/bind:9.9.5-20170129

Alternatively, you can use the sample docker-compose.yml file to start the container using Docker Compose.

When the container is started the Webmin service is also started and is accessible from the web browser at http://localhost:10000. Login to Webmin with the username root and password password. Specify --env ROOT_PASSWORD=secretpassword on the docker run command to set a password of your choosing.

The launch of Webmin can be disabled by adding --env WEBMIN_ENABLED=false to the docker run command. Note that the ROOT_PASSWORD parameter has no effect when the launch of Webmin is disabled.

Testing DNS Server

You can customize the launch command of BIND server by specifying arguments to named on the docker run command. For example the following command prints the help menu of named command:

docker run --name bind -it --rm \
--publish 53:53/tcp --publish 53:53/udp --publish 10000:10000/tcp \
--volume /srv/docker/bind:/data \
sameersbn/bind:9.9.5-20170129 -h

For the BIND to preserve its state across container shutdown and startup you should mount a volume at /data.

SELinux users should update the security context of the host mount point so that it plays nicely with Docker:

mkdir -p /srv/docker/bind
chcon -Rt svirt_sandbox_file_t /srv/docker/bind

Deployment and Maintenance

To upgrade the BIND DNS Docker image

Download the updated Docker image:

docker pull sameersbn/bind:9.9.5-20170129

Stop the currently running image:

docker stop bind

Remove the stopped container

docker rm -v bind

Start the updated image

docker run -name bind -d \ [OPTIONS] \ sameersbn/bind:9.9.5-20170129

Open the web browser to https://172.17.42.1:10000 and login to webmin as user root and password SecretPassword. This will give you the possibility to configure your DNS server using the Webmin UI.

Conclusion

For debugging and maintenance purposes you may want access the containers shell. If you are using Docker version 1.3.0 or higher you can access a running containers shell by starting bash using docker exec:

docker exec -it bind bash

This runs the Docker DNS server.

Filed Under : CONTAINERS, LINUX HOWTO

Tagged With : , ,

Free Linux Ebook to Download

Leave a Reply

All comments are subject to moderation.