Docker CloudFlare DDNS
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 and aarch64 devices, including the Raspberry Pi.
Image Variants
Image Tag | Architecture | OS |
---|---|---|
amd64 | x64 | Alpine Linux |
aarch64 | arm64v8 | Alpine Linux |
Usage
Quick Setup:
docker run \
-e API_KEY=Cloudflare API token \
-e ZONE=example.org \
-e SUBDOMAIN=prueba \
-e PROXIED=false \
juanico/cloudflare:<tag>
Parameters
--restart=always
- ensure the container restarts automatically after host reboot.-e API_KEY
- Your CloudFlare scoped API token. See the Creating a Cloudflare API token below. RequiredAPI_KEY_FILE
- Path to load your CloudFlare scoped API token from (e.g. a Docker secret). If bothAPI_KEY_FILE
andAPI_KEY
are specified,API_KEY_FILE
takes precedence.
-e ZONE
- The DNS zone that DDNS updates should be applied to. RequiredZONE_FILE
- Path to load your CloudFlare DNS Zone from (e.g. a Docker secret). If bothZONE_FILE
andZONE
are specified,ZONE_FILE
takes precedence.
-e SUBDOMAIN
- A subdomain of theZONE
to write DNS changes to. If this is not supplied the root zone will be used.SUBDOMAIN_FILE
- Path to load your CloudFlare DNS Subdomain from (e.g. a Docker secret). If bothSUBDOMAIN_FILE
andSUBDOMAIN
are specified,SUBDOMAIN_FILE
takes precedence.
Optional Parameters
-e PROXIED
- Set totrue
to make traffic go through the CloudFlare CDN. Defaults tofalse
.-e RRTYPE=A
- Set toAAAA
to use set IPv6 records instead of IPv4 records. Defaults toA
for IPv4 records.-e DELETE_ON_STOP
- Set totrue
to have the dns record deleted when the container is stopped. Defaults tofalse
.-e INTERFACE=tun0
- Set totun0
to have the IP pulled from a network interface namedtun0
. If this is not supplied the public IP will be used instead. Requires--network host
run argument.-e CUSTOM_LOOKUP_CMD="echo '1.1.1.1'"
- Set to any shell command to run them and have the IP pulled from the standard output. Leave unset to use default IP address detection methods.-e DNS_SERVER=10.0.0.2
- Set to the IP address of the DNS server you would like to use. Defaults to 1.1.1.1 otherwise.-e CRON="@daily"
- Set your own custom CRON value before the exec portion. Defaults to every 5 minutes -*/5 * * * *
.
Depreciated Parameters
-e EMAIL
- Your CloudFlare email address when using an Account-level token. This variable MUST NOT be set when using a scoped API token.
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:
- Click Create Token
- Provide the token a name, for example,
cloudflare-ddns
- Grant the token the following permissions:
- Zone - Zone Settings - Read
- Zone - Zone - Read
- Zone - DNS - Edit
- Set the zone resources to:
- Include - All zones
- Complete the wizard and copy the generated token into the
API_KEY
variable for the container
Multiple Domains
If you need multiple records pointing to your public IP address you can create CNAME records in CloudFlare.
IPv6
If you're wanting to set IPv6 records set the envrionment variable RRTYPE=AAAA
. You will also need to run docker with IPv6 support, or run the container with host networking enabled.
Docker Compose
If you prefer to use docker Compose:
version: '2'
services:
cloudflare-ddns:
image: juanico/cloudflare:<tag>
restart: always
environment:
- API_KEY=Cloudflare API token
#- EMAIL=email
- ZONE=example.org #solo el dominio
- SUBDOMAIN=prueba #solo el subdominio sin el dominio
- PROXIED=false