Tunneling

Cloudflare

This guide explains how to set up Cloudflare Tunnels and connect them to your own domain, including domain configuration, Docker setup, and connecting running services. Useful links at the bottom of the page.

Setup

Step 1 — Connect Your Domain to Cloudflare

  1. Create a Cloudflare Account Go to https://dash.cloudflare.com (opens in a new tab) and create an account if you don’t already have one.
  2. Add Your Domain • In the dashboard, click Add a Site. • Enter your domain name (e.g. myapp.com) and choose the Free plan (or higher if needed). • Cloudflare will scan your existing DNS records automatically.
  3. Update Nameservers • Cloudflare will provide you with two nameservers (e.g. amy.ns.cloudflare.com and john.ns.cloudflare.com). • Log in to your domain registrar (e.g. Google Domains, Namecheap, GoDaddy). • Replace the existing nameservers with the ones provided by Cloudflare. • Wait for propagation (usually takes 5–30 minutes).
  4. Verify Domain Connection • Once propagated, your domain will show as Active in the Cloudflare dashboard.

Step 2 — Create a Cloudflare Tunnel with Docker

Cloudflare Tunnels let you securely connect your local or containerized services to the internet without exposing public IPs or opening ports.

  • Generate a Tunnel Token
    1. Go to Zero Trust Dashboard → https://one.dash.cloudflare.com (opens in a new tab)
    2. Navigate to Access → Tunnels
    3. Click Create a Tunnel
    4. Give it a name (e.g. myapp-tunnel)
    5. Copy the generated Tunnel Token — you’ll need it in the next step

️ Step 3 — Configure the Tunnel to Point to Your Service

Using config.yml

For more control, you can use a configuration file. Create a directory, e.g. cloudflare-config, and inside it add a config.yml file:

config.yml
tunnel: <TUNNEL_ID>
credentials-file: /home/nonroot/.cloudflared/<TUNNEL_ID>.json
 
ingress:
  - hostname: api.myapp.com
    service: http://host.docker.internal:8080
  - hostname: frontend.myapp.com
    service: http://host.docker.internal:5173
  - service: http_status:404

Useful links