Install Docker

Update the repo to get latest versions

sudo apt update

Install the latest version

sudo apt install docker.io

Set Docker to start on startup

sudo systemctl enable --now docker

Give your user permissions to docker, replacing user with your username

sudo usermod -aG docker user

Once you have run this command close and reopen your session if you accessing remotely. This is to apply the permissions in the above step

Test it has installed correctly by getting the docker version

docker --version

Docker Compose

I also install docker-compose as some dockers need you to compose from a yml file. This downloads v2.16.0, just change this if the version updates to a later version

sudo curl -L "https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Give permissions to this

sudo chmod +x /usr/local/bin/docker-compose

Test it has installed correctly by getting the docker-compose version

docker-compose --version

Get API key from cloudflare-dns

Log in and navigate to api-tokens page in your cloudflare account. Link at time of writing is https://dash.cloudflare.com/profile/api-tokens

Create a new token, and select custom token at the bottom.

Give your token a name and give it the following permissions.

Zone > Zone Settings > Read Zone > Zone > Read Zone > DNS > Edit

Click continue, and make a note of the API token given to you.

Install Cloudflare-ddns

I keep all my dockers in a dockers folder in my home directory. If it doesn’t exist already, create this folder:-

mkdir ~/dockers

Now create a folder for cloudflare-dns to live in.

mkdir ~/dockers/cloudflare-dns

Change directory to this folder

cd ~/dockers/cloudflare-dns

Create a docker-compose.yml file

nano docker-compose.yml

Paste the following. Copy the API key from Cloudflare you created earlier instead of copiedfromapitokenfromcloudflare. Change the zone field domain.com to the domain name hosted by cloudflare you want to update. I use a subdomain to update instead of it updating the root of the domain, so you change subdomain dns to whatever you want, or you can comment it out if want to update the root.

version: '2'
services: 
   cloudflare-ddns:
      image: oznu/cloudflare-ddns:latest
      container_name: cloudflare-ddns
      restart: always
      environment:
         - API_KEY=copiedfromapitokenfromcloudflare
         - ZONE=domain.com
         - SUBDOMAIN=dns
         # - proxied=false 

Save the file with ctl + x, then y to save.

Run the docker-compose file with the following:-

docker-compose up -d

First run

After it runs, log int cloudflare, and go to the dns management page, you should now see the record you set in the docker-compose file updated with your public IP.