Public | Automated Build

Last pushed: a day ago
Short Description
DNS connected to Cloudflare DNS over TLS
Full Description

Cloudflare DNS over TLS Docker container

DNS caching server connected to Cloudflare DNS over TLS (IPv4 and IPv6) with DNSSEC, DNS rebinding protection, built-in Docker healthcheck and malicious IPs + hostnames blocking

10 Nov 2018: The port binding is back to 53:53/udp and the container runs without root privileges
This is thanks to setcap 'cap_net_bind_service=+ep' /usr/sbin/unbound allowing Unbound to bind to well known ports

Image size RAM usage CPU usage
19.4MB 13.2MB to 70MB Low

It is based on:

It also uses DNS rebinding protection and DNSSEC Validation:

You can also block additional domains of your choice, amongst other things, see the Extra section

Diagrams are shown for router and client-by-client configurations in the Connect clients to it section.

Testing it

docker run -it --rm --name cloudflare-dns-tls -p 53:53/udp \
  • The VERBOSITY environment variable goes from 0 (no log) to 5 (full debug log) and defaults to 1
  • The VERBOSITY_DETAILS environment variable goes from 0 to 4 and defaults to 0 (higher means more details)
  • The BLOCK_MALICIOUS environment variable can be set to 'on' or 'off' and defaults to 'on' (note that it consumes about 50MB of additional RAM). It blocks malicious IP addresses and malicious hostnames from being resolved.
  • The LISTENINGPORT environment variable sets the UDP port on which the Unbound DNS server should listen to (internally), and defaults to 53

You can check the verbose output with:

docker logs -f cloudflare-dns-tls

See the Connect clients to it section to finish testing.

Run it as a daemon

docker run -d -p 53:53/udp qmcgaw/cloudflare-dns-server

or use docker-compose.yml with:

docker-compose up -d

Connect clients to it

Option 1: Router (recommended)

Block the UDP 53 outgoing port on your router firewall so that all DNS traffic must go through this container.

All machines connected to your router will use the encrypted DNS by default

Configure your router to use the LAN IP address of your Docker host as its primary DNS address.

  • Access your router page, usually at and login with your credentials
  • Change the DNS settings, which are usually located in Connection settings / Advanced / DNS server
  • If a secondary fallback DNS address is required, use a dull ip address such as the router's IP to force traffic to only go through this container

Option 2: Client, one by one

You have to configure each machine connected to your router to use the Docker host as their DNS server.

Docker containers

Connect other Docker containers by specifying the DNS to be the host IP address

docker run -it --rm --dns= alpine

For docker-compose.yml:

version: '3'
    image: alpine
    network_mode: bridge

If the containers are in the same virtual network, you can simply set the dns to the LAN IP address of the DNS container (i.e.


  1. Open the control panel and follow the instructions shown on the screenshots below.

Enter the IP Address of your Docker host as the Preferred DNS server ( in my case)
You can set the Cloudflare DNS server address as an alternate DNS server although you might want to
leave this blank so that no domain name request is in plaintext.

When closing, Windows should try to identify any potential problems.
If everything is fine, you should see the following message:

Mac OS

Follow the instructions at


You probably know how to do that. Otherwise you can usually modify the first line of /etc/resolv.conf by changing the IP address
of your DNS server.


See this


See this


Block domains of your choice

  1. Create a file on your host include.conf
  2. Write the following to the file to block for example:

     local-zone: "" static
  3. Change the ownership and permissions of include.conf:

     chown 1000:1000 include.conf
     chmod 400 include.conf
  4. Launch the Docker container with:

     docker run -it --rm -p 53:53/udp \
     -v $(pwd)/include.conf:/etc/unbound/include.conf \

Build all the images yourself

docker build -t qmcgaw/malicious-ips
docker build -t qmcgaw/malicious-hostnames
docker build -t qmcgaw/dns-rootanchor
docker build -t qmcgaw/cloudflare-dns-server

Firewall considerations

This container requires the following connections:

  • UDP 53 Inbound (only if used externally)
  • TCP 853 Outbound to and


  • [ ] Build Unbound binary at image build stage
Docker Pull Command
Source Repository