Bobcares

Docker Cloudflare DDNS

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=always
    – After the host reboots, this makes sure the container restarts automatically.
  • -e API_KEY
    – Our Cloudflare API token with a specific scope. See the section below on how to create a Cloudflare API token. Required
    API_KEY_FILE
    – From where we’ll get our Cloudflare scoped API token.
    API_KEY_FILE
    takes precedence if both
    API_KEY_FILE
    and
    API_KEY
    are there.
  • -e ZONE
    – 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 SUBDOMAIN
    A subdomain of the zone where DNS changes can be made. If this is not there, the root zone will be used.
    SUBDOMAIN_FILE
    – The path from which our Cloudflare DNS Subdomain is loaded.
    SUBDOMAIN_FILE
    takes precedence if both
    SUBDOMAIN_FILE
    and
    SUBDOMAIN
    are there.

Optional Parameters

  • -e PROXIED
    – If
    true
    , traffic will be routed through the Cloudflare CDN.
    false
    is the default value.
  • -e RRTYPE=A
    – To use IPv6 records instead of IPv4 records, set
    AAAA
    . For IPv4 records, it defaults to
    A
    .
  • -e DELETE_ON_STOP
    – If
    true
    , the dns record will be deleted when the container is stopped.
    false
    is the default value.
  • -e INTERFACE=tun0
    – Set to
    tun0
    to get the IP address from a
    tun0
    network interface. If this field is left blank, the public IP address will be used instead. The
    --network host
    run argument is required.
  • -e CUSTOM_LOOKUP_CMD="echo '1.1.1.1'"
    – 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.2
    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"
    – Before the exec portion, set our own custom CRON value. Defaults value is set to every 5 minutes –
    */5 * * * *
    .

Depreciated Parameters

  • -e EMAIL
    – 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-ddns
  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_KEY
    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=AAAA
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!

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF