15/10/20 Notes
Containerising BIND
# I use this dockerfile to create an image that can serve my own DNS zone.
# I run the docker container using:
# /usr/bin/docker run -d -t -p 53:53/udp --name insert-container-name insert-image-name bash -c "service named start && sleep infinity"

# Download Ubuntu base OS
FROM ubuntu:20.04

# LABEL about this custom image
LABEL maintainer="beare84@gmail.com"
LABEL version="1.0"
LABEL description="Runs my DNS zone."

# Disable Prompt During Packages Installation
ARG DEBIAN_FRONTEND=noninteractive

# Update Ubuntu Software repository
RUN apt-get update -y && apt-get upgrade -y

# Install DNS software
RUN apt-get install -y bind9

# Create the zone file configuration
RUN echo 'zone "tayicseua.com" {\n\
type master;\n\
notify no;\n\
file "/etc/bind/db.tayicseua.com";\n\
allow-transfer {\n\
"none";\n\
};\n\
};'\
> /etc/bind/named.conf.local

# Create the zone file
RUN echo $'TTL 3600\n\
@ IN SOA ns1.tayicseua.com. postmaster.tayicseua.com. (\n\
2014032705 ; Serial\n\
12H ; Refresh\n\
1H ; Retry\n\
2W ; Expire\n\
3H ) ; Negative Cache TTL\n\
;\n\
@ IN NS ns1.tayicseua.com.\n\
@ IN NS ns2.tayicseua.com.\n\
@ IN A 45.76.120.130\n\
ns1 IN A 45.76.120.130\n\
ns2 IN A 45.76.120.130\n\
www IN A 45.76.120.130\n\
beare IN A 45.76.120.130\n\
www.beare IN A 45.76.120.130\n\
khounkongleng IN A 45.76.120.130\n\
www.khounkongleng IN A 45.76.120.130'\
> /etc/bind/db.tayicseua.com

# Enforce correct permissions
RUN chown root:bind /etc/bind/db.tayicseua.com
RUN chown root:bind /etc/bind/named.conf.local
RUN chmod 644 /etc/bind/db.tayicseua.com
RUN chmod 644 /etc/bind/named.conf.local

# Listen on port 53
EXPOSE 53/udp