Bobcares

Docker Cloudflare DDNS

by | Apr 27, 2022

Docker Cloudflare DDNS image will allow us to use the free CloudFlare DNS Service as a Dynamic DNS Provider (DDNS). So, In this article, we’ll dig a bit deeper into the details.

As part of our Docker Hosting Support, Bobcares provides solutions to all queries, large and small.

Let’s take a closer look at Docker cloud-flare DDNS.

Docker Cloudflare DDNS

Cloudflare DDNS is a Docker image that automatically updates DNS records on Cloudflare. However, this small Alpine Linux-based Docker image allows us to use CloudFlare’s free DNS service as a dynamic DNS provider (DDNS).

Most importantly, this is a multi-arch image that will run on devices like the Raspberry Pi that are amd64, aarch64, and armhf.

Image Variants


docker cloudflare ddns

Usage

The setup is simple.

docker run \
  -e API_KEY=xxxxxxx \
  -e ZONE=example.com \
  -e SUBDOMAIN=subdomain \
  oznu/cloudflare-ddns

Parameters

  • --restart=alwaysCopy Code
    – After the host reboots, this makes sure the container restarts automatically.
  • -e API_KEYCopy Code
    – Our Cloudflare API token with a specific scope. See the section below on how to create a Cloudflare API token. Required
    API_KEY_FILECopy Code
    – From where we’ll get our Cloudflare scoped API token.
    API_KEY_FILECopy Code
    takes precedence if both
    API_KEY_FILECopy Code
    and
    API_KEYCopy Code
    are there.
  • -e ZONECopy Code
    – The DNS zone should receive DDNS updates. Required

    ZONE_FILE – From where we want to load our Cloudflare DNS Zone. If we specify both ZONE FILE and ZONE, ZONE FILE takes precedence.

  • -e SUBDOMAINCopy Code
    A subdomain of the zone where DNS changes can be made. If this is not there, the root zone will be used.
    SUBDOMAIN_FILECopy Code
    – The path from which our Cloudflare DNS Subdomain is loaded.
    SUBDOMAIN_FILECopy Code
    takes precedence if both
    SUBDOMAIN_FILECopy Code
    and
    SUBDOMAINCopy Code
    are there.

Optional Parameters

  • -e PROXIEDCopy Code
    – If
    trueCopy Code
    , traffic will be routed through the Cloudflare CDN.
    falseCopy Code
    is the default value.
  • -e RRTYPE=ACopy Code
    – To use IPv6 records instead of IPv4 records, set
    AAAACopy Code
    . For IPv4 records, it defaults to
    ACopy Code
    .
  • -e DELETE_ON_STOPCopy Code
    – If
    trueCopy Code
    , the dns record will be deleted when the container is stopped.
    falseCopy Code
    is the default value.
  • -e INTERFACE=tun0Copy Code
    – Set to
    tun0Copy Code
    to get the IP address from a
    tun0Copy Code
    network interface. If this field is left blank, the public IP address will be used instead. The
    --network hostCopy Code
    run argument is required.
  • -e CUSTOM_LOOKUP_CMD="echo '1.1.1.1'"Copy Code
    – Set to any shell command to execute them, with the IP retrieved from the standard output. To use the default IP address detection methods, leave it unchecked.
  • -e DNS_SERVER=10.0.0.2Copy Code
    Set the IP address of the DNS server we’d like to use to this value. Otherwise, it falls back to 1.1.1.1.
  • -e CRON="@daily"Copy Code
    – Before the exec portion, set our own custom CRON value. Defaults value is set to every 5 minutes –
    */5 * * * *Copy Code
    .

Depreciated Parameters

  • -e EMAILCopy Code
    – When using an Account-level token, our CloudFlare email address is used. When using a scoped API token, this variable MUST NOT be set.

Creating a Cloudflare API token

Go to Dashboard > profile > api-tokens and follow these steps to create a CloudFlare API token for the DNS zone:
  1. Firstly, To create a token, click the Create Token button.
  2. Secondly, Give the token a name. For example,
    cloudflare-ddnsCopy Code
  3. Permissions should be granted to the token as follows:
    Read permissions for Zone-Zone Settings
    Read permissions for Zone-Zone
    Edit permissions forZone – DNS
  4. After that, set the resources for the zone to:
    Include – All zones
  5. Further, Complete the wizard and paste the generated token into the container’s
    API_KEYCopy Code
    variable.

Multiple Domains

Create CNAME records in CloudFlare if we need multiple records pointing to the public IP address.

IPv6

Set the environment variable 

RRTYPE=AAAACopy Code
if we want to set IPv6 records.
Moreover, we’ll also need docker with IPv6 support or a container with host networking enabled.

Docker Compose

On the other hand, if we use Docker Compose, follow these steps:


version: '2'
services:
  cloudflare-ddns:
    image: oznu/cloudflare-ddns:latest
    restart: always
    environment:
      - API_KEY=xxxxxxx
      - ZONE=domainname.com
      - SUBDOMAIN=subdomain.domainname.com
      - PROXIED=false

 

[Looking for a solution to another query? We are just a click away.]

Conclusion

In conclusion, Docker Cloudflare DDNS is a simple Docker image that wraps an example script to dynamically update a Cloudflare DNS record.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

4 Comments

  1. Martin

    Hi,

    can i use diffrent Domains set in one Compose File?
    can i set IPV4 and IPV6 for Domain in one Compose File?

    Reply
    • Hiba Razak

      Yes you can have both IPv4 and IPv6 addresses associated with the same dns name.

      Reply
  2. paul

    can i use a wildcard for the subdomain to capture all subdomains? e.g. *.example.com ?

    Reply
    • Hiba Razak

      Yes, you can use a wildcard for the subdomain to capture all subdomains using a pattern like “*.example.com” in Docker Cloudflare DDNS.

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Speed issues driving customers away?
We’ve got your back!