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.
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: true03Declare 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.
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 -1Key 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
- Cloudflare Tunnel: create a remotely managed tunneldevelopers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/
- Cloudflare Tunnel: tunnel with firewalldevelopers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/configure-tunnels/tunnel-with-firewall/
- Cloudflare Access: self-hosted applicationdevelopers.cloudflare.com/learning-paths/clientless-access/access-application/create-access-app/