Dockerfile to create a Docker container image for BIND DNS server.
BIND is 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.
If you find this image useful here's how you can help:
- Send a pull request with your awesome features and bug fixes
- Help users resolve their issues.
Before reporting your issue please try updating Docker to the latest version and check if it resolves the issue. Refer to the Docker installation guide for instructions.
SELinux users should try disabling SELinux using the command setenforce 0 to see if it resolves the issue.
If the above recommendations do not help then report your issue along with the following information:
- Output of the
docker versionanddocker infocommands - The
docker runcommand ordocker-compose.ymlused to start the image. Mask out the sensitive bits.
Automated builds of the image are available on Dockerhub and is the recommended method of installation.
docker pull labbsr0x/dns-bind9Alternatively you can build the image yourself.
docker build -t labbsr0x/dns-bind9 github.com/labbsr0x/docker-dns-bind9or
make buildStart BIND using:
docker run --rm --name bind -d --publish 53:53/tcp --publish 53:53/udp --volume ${PWD}/.bind9:/data labbsr0x/dns-bind9or
make docker-runAlternatively, you can use the sample docker-compose.yml file to start the container using Docker Compose
For the BIND to preserve its state across container shutdown and startup you should mount a volume at /data.
The Quickstart command already mounts a volume for persistence.
mkdir -p .bind9To upgrade to newer releases:
- Download the updated Docker image:
docker pull labbsr0x/dns-bind9- Stop the currently running image:
docker stop bindor
make docker-stop- Remove the stopped container
docker rm -v bindand
rm -rf .bind9- Start the updated image
docker run -name bind -d \
[OPTIONS] \
labbsr0x/dns-bind9For 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- Two servers that will be our DNS name servers with the following features installed. Referred as ns1 and ns2.
- docker
- docker-compose
- git
- newdomain.com domain as an example.
| Servers | Description | Example FQDN | Example IP |
|---|---|---|---|
| ns1 | Primary DNS server | ns1.newdomain.com | 10.0.10.1 |
| ns2 | Secondary DNS server | ns2.newdomain.com | 10.0.10.2 |
Clone github project on ns1 server
git clone https://github.com/labbsr0x/docker-dns-bind9.gitCreate a directory that will be used as DNS volume
mkdir /opt/bind9Copy primary DNS directory and docker-compose file
cp -r /opt/docker-dns-bind9/example/primary /opt/bind9/.
cp /opt/docker-dns-bind9/docker-compose.yml /opt/bind9/.Set volume path in docker-compose.yml
...
volumes:
- /opt/bind9/primary:/data # Change volume pathRename zone file db.example.com to name of desired zone.
In this example we will rename db.example.com to db.newdomain.com
mv /opt/bind9/primary/bind/etc/db.example.com /opt/bind9/primary/bind/etc/db.novodominio.comIn zone file change everywhere that are example.com to new zone and setup IP.
In this example we will change example.com to newdomain.com
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA newdomain.com. root.newdomain.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1.newdomain.com.
@ IN NS ns2.newdomain.com.
@ IN A 127.0.0.1
@ IN AAAA ::1
ns1 A 10.0.10.1 ; Change to the desired NS1 IP
ns2 A 10.0.10.2 ; Change to the desired NS2 IPConfig the new db file and new zone in named.conf.default-zones.
In this example we will change example.com to newdomain.com and the file path db.example.com to db.newdomain.com and set Secondary DNS IP in allow-transfer.
...
zone "newdomain.com" { // Change to desired zone
type master;
file "/etc/bind/db.newdomain.com"; // Change to zone file path
allow-transfer {10.0.10.2; }; // Change to Secondary DNS IP
// allow-update {
// key "example.com";
// };
};
...Start the new DNS with docker-compose.
docker-compose up -dClone github project on ns2 server
git clone https://github.com/labbsr0x/docker-dns-bind9.gitCreate a directory that will be used as DNS volume
mkdir /opt/bind9Copy secondary DNS directory and docker-compose file
cp -r /opt/docker-dns-bind9/example/secondary /opt/bind9/.
cp /opt/docker-dns-bind9/docker-compose.yml /opt/bind9/.Set volume path in docker-compose.yml
...
volumes:
- /opt/bind9/secondary:/data # Change volume pathConfig the new db file and new zone in named.conf.default-zones.
In this example we will change example.com to newdomain.com and the file path db.example.com to db.newdomain.com and set Primary DNS IP in master field.
...
zone "newdomain.com" { // Change to desired zone
type slave;
file "/etc/bind/db.newdomain.com"; // Change to zone file path
masters {10.0.10.1;}; // Change to Primary DNS IP
};
...Start the secondary DNS with docker-compose.
docker-compose up -ddig -t ns newdomain.com @localhost +shortResult
ns1.newdomain.com.
ns2.newdomain.com.Example in Portuguese (pt_BR) on fabiotavarespr.dev's blog
References used in these projects