Skip to content

Instantly share code, notes, and snippets.

@Vexcited
Created September 16, 2025 23:53
Show Gist options
  • Save Vexcited/7e766966fdd0df717935fba934ed2b60 to your computer and use it in GitHub Desktop.
Save Vexcited/7e766966fdd0df717935fba934ed2b60 to your computer and use it in GitHub Desktop.
Deploy a cloudflared instance using Docker Compose.

Let's setup a Cloudflare Tunnel using Docker Compose.
Our goal will be to proxy an entire app deployed in an internal network to our own subdomain publicly.

Create a tunnel

https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-remote-tunnel/

  1. Login to Zero Trust
  2. Go to Networks > Tunnels > Add a tunnel
  3. Choose Cloudflared for the connector type and select Next
  4. Enter a name for your tunnel
  5. Save tunnel!

Create connector

Grab the given token from the page and write the following docker-compose.yml file.

version: 2 # update according to your needs!

services:
  cloudflared:
    image: cloudflare/cloudflared:latest
    restart: always
    command: >
      tunnel --no-autoupdate run --token ${CLOUDFLARED_TUNNEL_TOKEN}

You'll also need a .env file with the following content.

CLOUDFLARED_TUNNEL_TOKEN="your-token"

Deploy this compose configuration!

Configure

  1. Choose a subdomain (optional), a domain and a path (optional) for the hostname of the thunnel.
  2. Select what type of service you want to tunnel

If you're proxying an HTTPS service, you can add more settings such as HTTP > HTTP Host Header which sets the HTTP Host header on requests sent to the local service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment