Skip to content
Dorian FINKEL
CloudflareZero TrustDockerTutorial · 2026 · 2 min read · Updated 9 October 2026
Level · BeginnerDuration · 20 min

Publish a service with Cloudflare Tunnel and Docker

A cloudflared container, a token, a hostname declared in the dashboard: the service is online over HTTPS with no port open on the router. And Cloudflare Access in front of what must stay private.

Prerequisites

  • A domain whose DNS is managed at Cloudflare
  • Docker and Docker Compose installed
  • The firewall allows outbound connections on port 7844 (TCP and UDP)

01Create the tunnel

In the Cloudflare Zero Trust dashboard: Networks › Tunnels › Create a tunnel, type Cloudflared. Pick a name, then the Docker environment: the suggested command contains the tunnel token. This is “remotely managed” mode, recommended by Cloudflare with Docker: routes are configured in the dashboard.

The token alone is enough to run the tunnel: treat it like a password.

02The container

The token is read from the TUNNEL_TOKEN variable, stored in an unversioned .env file. Placed on the same Docker network as the services, the connector reaches them by container name.

Example · compose.yaml
services:
  cloudflared:
    image: cloudflare/cloudflared:<version>   # see the releases on GitHub
    restart: unless-stopped
    command: tunnel --no-autoupdate run
    environment:
      - TUNNEL_TOKEN=${TUNNEL_TOKEN}
    networks: [web]

networks:
  web:
    external: true

03Declare a hostname

In the tunnel, Public Hostname tab › Add: a subdomain, and the internal service, for example http://uptime-kuma:3001. Cloudflare creates the DNS record itself (a CNAME to the tunnel). Any name that isn’t declared gets a 404 error.

04Protect with identity

For an admin interface, create a Self-hosted Access application on that hostname, with an “Allow” policy limited to your email address (one-time code) or your identity provider. The visitor authenticates at Cloudflare before their request reaches the tunnel.

05Verify

The tunnel shows as “Healthy” in the dashboard, and the container log shows several registered connections to different data centres, for redundancy.

Example · Shell
docker compose up -d
docker compose logs cloudflared | grep -i "registered tunnel connection"

# From 4G: the service answers, no port is open at home
curl -sI https://status.example.com | head -1

Key takeaways

  • Remotely managed mode: a token, routes in the dashboard.
  • The token is a secret: .env file, never in Git.
  • Same Docker network: the service is reached by name.
  • Access in front of every admin interface.
  • Only outbound port 7844 is needed.

Documentation-reserved names.

Official sources