rycochet/docker-cloudflare-ddns

By rycochet

Updated over 1 year ago

A small Docker image that allows you to use CloudFlare as a DDNS / DynDNS Provider.

Image
Networking
0

351

rycochet/docker-cloudflare-ddns repository overview

Docker CloudFlare DDNS

GitHub Actions Workflow Status GitHub contributors Docker Pulls Docker Image Size

This small Alpine Linux based Docker image will allow you to use the free CloudFlare DNS Service as a Dynamic DNS Provider (DDNS).

This is a multi-arch image and will run on amd64, aarch64, and armhf devices, including the Raspberry Pi.

Usage

Docker

Quick Setup:

docker run \
  -e API_KEY=<apikey> \
  -e ZONE=<mydomain> \
  -e SUBDOMAIN=@,www \
  ghcr.io/rycochet/docker-cloudflare-ddns:latest
Docker Compose

If you prefer to use Docker Compose:

services:
  cloudflare-ddns:
    image: ghcr.io/rycochet/docker-cloudflare-ddns:latest
    restart: always
    environment:
      - API_KEY=<apikey>
      - ZONE=<mydomain>
      - SUBDOMAIN=@,www

Environment Variables

NameDefinitionDefault
API_KEY or
API_KEY_FILE 1
Required
Your CloudFlare scoped API token. See Creating a Cloudflare API token below.
ZONE or
ZONE_FILE 1
Required
The DNS Zone (domain name) that DDNS updates should be applied to.
SUBDOMAIN or
SUBDOMAIN_FILE 1
One or more comma separated subdomains of the ZONE to write DNS changes to.
@ will update the root zone.
* will update the wildcard subdomain.
@
CRONSet your own custom CRON value for how often this runs.*/5 * * * * (every 5 minutes)
CUSTOM_LOOKUP_CMDA shell command to run that must print the IP on the standard output.
DELETE_ON_STOPDelete the DNS record when the container is stopped.false
DNS_SERVERThe IP address of the DNS server for automatic DNS lookups should ipify fail.1.1.1.1
EMAILDeprecated
Your CloudFlare email address when using an Account-level token. This variable MUST NOT be set when using a scoped API token.
INTERFACESet to tun0 to have the IP pulled from a network interface named tun0. If this is not supplied the public IP will be used instead.
Requires --network host run argument.
PROXIEDMake traffic go through the CloudFlare CDN.false
RRTYPEDNS record type:
A for IPv4.
AAAA for IPv6 (you will also need to run docker with IPv6 support, or run the container with host networking enabled).
A
WEBHOOK_URLSet to a webhook URL to send a message when the IP address changes.

Explanation on how this container works

The image is based on an alpine OS with S6 supervisor and the s6-overlay architecture.

It will find out the DNS address to use, then for each requested subdomain it will check if it needs to update, and only change if needed.

This runs (by default) every 5 minutes using cron. The default TTL (Auto) on Cloudflare is 5 minutes, so records are updated about as quickly as possible.

Creating a Cloudflare API token

To create a CloudFlare API token for your DNS zone go to https://dash.cloudflare.com/profile/api-tokens and follow these steps:

  1. Click Create Token.
  2. Use the Edit zone DNS Template.
  3. Provide the token a name, for example: cloudflare-ddns.
  4. Leave the Permissions unchanged (Zone - DNS - Edit).
  5. Set the Zone Resources to Include - All zones
  6. Click Continue to summary, then Create Token.
  7. Make a record of the token somewhere safe (such as a password manager) as you cannot view it again, and then use the token for the API_KEY variable.
Multiple Domains

If you need multiple records pointing to your public IP address you can create CNAME records in CloudFlare, or run multiple instances of the image with different options.

Supported Platforms
  • linux/386
  • linux/amd64
  • linux/arm/v6
  • linux/arm/v7
  • linux/arm64
  • linux/ppc64le
  • linux/riscv64
  • linux/s390x

License

Copyright (C) 2017-2025 oznu (original developer until 2020), two70, TThanhXuan, VSF1, sachasmart, enstyrka, aaronbolton, ian-otto, giorginogreg, Rycochet

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Footnotes

  1. Path to load your CloudFlare DNS Zone from (e.g. a Docker secret).
    If both normal and a _FILE parameter are specified the file takes precedence. 2 3

Tag summary

Content type

Image

Digest

sha256:7e22081a1

Size

24.3 MB

Last updated

over 1 year ago

docker pull rycochet/docker-cloudflare-ddns