Setting up your own CoreDNS DNS server in docker

· 1 min read
Setting up your own CoreDNS DNS server in docker

Hello! In this article, we'll set up our own DNS server to specify our own NS servers.

1) Create a folder, for example, coredns

mkdir coredns

2) In the coredns folder, create a file docker-compose.yml

services:
  coredns:
    image: coredns/coredns:1.14.4
    container_name: coredns
    restart: unless-stopped
    ports:
      - 53:53/tcp
      - 53:53/udp
    volumes:
      - ./config:/etc/coredns:ro
      - ./config/Corefile:/Corefile:ro

docker-compose.yml

3) In the coredns folder, create a config folder and create a Corefile file in it.

cd coredns && mkdir config
example.com {
    file /etc/coredns/zones/db.example.com
}

Corefile

4) We create a zones folder in the config folder for convenience, but this is not necessary.

cd config && mkdir zones

5) In the zones folder, create a zone file db.example.com

$ORIGIN kazhekin.com.
$TTL    86400
@       IN      SOA     judy.ns.kazhekin.com. admin.kazhekin.com. (
                              		2001062501 ; serial                     
			                        21600      ; refresh after 6 hours                     
			                        3600       ; retry after 1 hour                     
			                        604800     ; expire after 1 week                     
			                        86400 )    ; minimum TTL of 1 day 

@       IN      NS      judy.ns.kazhekin.com.
@       IN      NS      panam.ns.kazhekin.com.

judy.ns      IN        A           127.0.0.1
judy.ns      IN        AAAA        ::1
panam.ns     IN        A           127.0.0.1
panam.ns     IN        AAAA        ::1

@              IN      A           127.0.0.1
@              IN      AAAA        ::1

admin.kazhekin.com - this is the email address of the zone administrator admin@kazhekin.com

judy.ns.kazhekin.com - this is an authoritative DNS server.

6) In order for the Internet to know about the existence of our DNS servers, we need to add a glue record at the registrar.

7) launch the container

docker compose up -d