Installing A Cloudflare Docker On A Raspberry Pi 4 DDNS – Episode 8

7, Feb 2021 | Raspberry Pi Series | 1 comment

In today’s tutorial, we will be showing you how to install a Cloudflare docker that will work with Cloudflare’s free Dynamic IP service. This will allow your Raspberry PI to update your domain every time your networks public-facing IP address changes. This is Episode 8 in our Raspberry Pi Series.

This is only helpful for networks that use dynamic IP’s provided to them by their Internet Service Provider (ISP). Static IP’s are normally only issued to businesses that request them. However, in most domestic cases an IP will be Dynamic and change in line with the IP lease time or if the network gateway modem is restarted.

This is problematic if you host a public-facing server that needs to be accessed by internet traffic. This is where Cloudflare’s DNS services come in.

Not only is Cloudflare a great option for serving domain DNS to a network it can also add extra layers of security to your network by providing denial of service (DOS) protection as well as SSL/TLS.

You will need to have a domain name. If you already have one you can skip Step 1.

Difficulty=Medium

Step 1 – Purchase a Domain Name

We will be purchasing a domain name from our Domain provider of choice Namecheap. We have been using this company for over 10 years and highly recommend them as a domain provider.

Purchasing a Domain name from Namecheap:

Navigate to https://www.addictedtotech.net/namecheap which is an affiliate link. By using our link we get a small commission when you purchase a domain name. By doing so you are supporting our website and for this, we greatly appreciate it :).

Once you are at the homepage you can use the search box to find your new domain name. In our example, we are going to purchase addicted2tech.net domain to go along with our brand name.

Namecheap Domains

Go through the shopping cart and pay for your new domain.

Now you have your domain name we can move on to the next step

Step 2 – Add your domain to Cloudflare for DNS management

Navigate to Cloudflare https://www.cloudflare.com.

Create a Cloudflare account or sign in to your existing account.

Once logged in click on “Add Site” to add your new domain name to Cloudflare.

Enter your domain name and press “Add Site“.

Select a plan. The Free Cloudflare plan will work fine for DDNS. Select the “Free” plan and press “Continue“.

For now scroll to the bottom of the next page and click on “Continue“.

Once the DNS scan completes you will be at the “Review your DNS records” page.

In the next page, you will be given some Cloudflare nameservers. It will show you what your current domain names nameservers are and what they need to be replaced with.

Click on “Continue“.

Please note: Your nameservers will differ from the ones displayed above.

You will need to update these nameservers with your domain registrar. In our tutorial, we are using Namecheap.

Navigate in a new browser tab window to Namecheap’s website and log in with your account details.

Navigate to the Domain List page and click on the “Manage” button next to your Domain.

On the Domain Tab under NAMESERVERS click on the drop down arrow and select “Custom DNS“.

Add both Cloudflare nameserver IP’s to the Custom DNS and click the Green tick box to save the new settings.

Please note: The nameserver changes can take up to 24 hours to complete. I would recommend giving it a day or two to fully propagate before moving on with the next step.

DNS propagation is a process where DNS servers (which are public address directories that use an address (Domain name) and a number (IP Address) to locate devices/servers on the internet and their hosted services. There are thousands of DNS servers across the world that relay/sync off each other so they all need to update their directories with your new nameservers in order for your domain to work correctly.

You can check the status of the propagation by using third party DNS checking websites online. Here is one called whatsmydns.net. You mostly want to see green ticks on as many DNS server locations as possible. You may still get the odd red cross but this may be due to their servers being offline or some other network outage.

The final thing to do is to return to your Cloudflare account and click the “Done, check nameservers” button to initiate Cloudflare to scan and confirm that your new nameservers have propagated correctly.

If at this stage it fails. Wait for another few hours and try again.

Step 3 – Configuring Cloudflare (Cloudflare Quick Start Guide)

We will go down the list. Under step one Improve security we will press “On” for “Automatic HTTPS Rewrites“. Then click “Save“.

In the next section we will press “On” for “Always Use HTTPS” and click “Save

Under “Auto Minify” we will leave this setting at default and click “Save“.

In the final section under “Brotli” we will leave this “On” and click “Save“.

In the Summary section click the “Finish” button to exit the Quick Start Guide.

Once you have configured Cloudflare correctly and your domain has propagated you should get “Great news! Cloudflare is now protecting your site” appear on the Overview tab.

Step 4 – Creating A Cloudflare API key

From within the Cloudflare dashboard in the top right corner click on your profile icon then in the drop-down menu click “My Profile“.

Then in the My Profile section click on the “API Tokens” tab.

In the API Tokens page click on “Create Token

Navigate to the bottom of the Create API Token page and under Create Custom Token click on “Get Started“.

Once in the Create Custom Token page add the following:

Under Token Name give your token a name (Anything that makes sense to you)

Under Permissions we want to add 3 lines.

Set the following 3 entries and in the blurred out field below select your Cloudflare account email address from the dropdown list.

Once you have done all that click on “Continue To Summary“.

In the Summary page click on “Create Token“.

You should now be given your API code. Keep this in a safe place. Click the “Copy” button to copy the API key to memory. We will need this API key for our Docker container.

Step 5 – Creating A Cloudflare Docker Container In Portainer Using A Stack.

Open a new browser window and navigate to your Portainer container. In our example, we will use our local IP “https://192.168.2.5:9000“.

Once in the Portainer dashboard click on “Stacks” in the Left menu.

In the next page click on “Add Stack“.

Under Create stack give your Stack a name in our example we named ours “cloudflare“.

Copy the following docker-compose data into the Web Editor section. Edit the fields to match your own configuration settings.

version: '2'
services:
  cloudflare-ddns:
    image: oznu/cloudflare-ddns:latest
    restart: always
    environment:
      - PUID=1001 #Optional Enter Your Own Values
      - PGID=100 #Optional Enter Your Own Values
      - API_KEY=xxxxxxx #Enter Your Cloudflare API Key Here
      - ZONE=example.com #Enter Your Cloudflare Domain Name
      - PROXIED=true
Cloudflare Docker Stack Docker Compose

Now you have set all the correct values in your Stack you are ready to scroll to the bottom of the page and click on the “Deploy the stack“.

Note: This may take some time to complete.

To confirm the containers have been created click on the “Containers” tab in the left menu.

You should see that there is a new container for Cloudflare. To check it is working ok click on the log icon in the “Quick actions” column.

Check the log to make sure it looks similar to our output below.

Step 6 – Adding A Subdomain For Your Desired Service Container.

In our tutorial example, we are going to add a subdomain to Cloudflare so it is ready for our next episode Installing Nextcloud on Raspberry Pi 4 using Docker With Remote Access – Episode 9.

Navigate back to your Cloudflare dashboard and click on the “DNS” tab.

Under DNS management for (Your Domain name) click on the “Add record“.

Under Type select “CNAME” from the drop-down menu.

Under Name, this is where you add your subdomain. In our example, we have named it after our container “nextcloud

Under Target field just add the @ symbol.

Finally, under Proxy status turn off “Proxied” by clicking the orange Proxied icon and it should turn grey and the text should change to “DNS only” and click “Save“.

Please note: We want this connection to be proxied eventually but at this stage, we have not configured our NGINX Proxy Manager or TLS/SSL certificate for nextcloud.addicted2tech.net We will do this in our next Episode Installing Nextcloud on Raspberry Pi 4 using Docker With Remote Access – Episode 9.

This concludes today’s Episode. If you would like to support our work you can Like our content and Subscribe to our Youtube Channel.

We also have Amazon affiliate links for all our recommended products. Just so you know, we may collect a share of sales or other compensation from the links on our website. Thank you if you use our links, we really appreciate it!.

We need your support.

We hope you enjoyed this episode and that it was helpful and you got benefit out of it.

If you did, please consider supporting our channel by Subscribing to our YouTube channel, and liking and sharing our content.

You can also make a donation via Paypal or become a Patreon if you wish to do so. You can also follow us on Facebook or Twitter.

If you have any questions or any requests please ask in the comments below or on YouTube.

1 Comment

  1. A

    Hi! I wasn’t able to access nextcloud from the web until I changed to the following : has self-signed SSL certificates, use the Full SSL option

    Reply

Submit a Comment

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

<a href="https://www.addictedtotech.net/author/attadmin/" target="_self">Addicted2Tech</a>

Addicted2Tech

We love technology and enjoy sharing helpful FREE content for others to enjoy. We believe in community. If you like what we do please support us by sharing and liking our tutorials & Subscribing to our YouTube channel. You can also follow us on social media.

Support Our Work!

Donate Via Patreon

Raspberry Pi 4 Model B [8GB] RAM Single Board Computer

Last update on 2022-12-01 / Affiliate links / Images from Amazon Product Advertising API

CanaKit Raspberry Pi 4 Extreme Kit – 128GB Edition (4GB RAM)

Last update on 2022-12-01 / Affiliate links / Images from Amazon Product Advertising API

We Are An Affiliate!

Just so you know, we may collect a share of sales or other compensation from the links on this page. As an Amazon Associate I earn from qualifying purchases.

The Affiliate link recommendations come at no extra cost to you.

We hope you love the products we recommend!

Thank you if you use our links, we really appreciate it!

Related Posts