Labelgate

cloudflared Setup

Run the cloudflared connector next to Labelgate.

Use this when you publish containers with labelgate.tunnel.* labels. Labelgate writes the tunnel routes to Cloudflare. cloudflared is the connector that carries the traffic, so it must run too.

1. Create the tunnel

  1. Open Cloudflare Zero Trust → Networks → Tunnels → Create a tunnel → Cloudflared.
  2. Name it and save. Skip the "public hostname" step: Labelgate adds those.
  3. Copy two values:
    • the tunnel ID → LABELGATE_CLOUDFLARE_TUNNEL_ID (for Labelgate);
    • the token from the install command (the long string after --token) → TUNNEL_TOKEN (for cloudflared).

Labelgate also needs LABELGATE_CLOUDFLARE_ACCOUNT_ID, the account that owns the tunnel.

2. Add cloudflared to Compose

compose.yaml
services:
  cloudflared:
    image: cloudflare/cloudflared:latest
    restart: unless-stopped
    command: tunnel --no-autoupdate run --token ${TUNNEL_TOKEN}

  app:
    image: nginx:alpine
    labels:
      labelgate.tunnel.app.hostname: "app.example.com"
      labelgate.tunnel.app.service: "http://app:80"

cloudflared picks up new routes by itself. You never restart it when labels change.

For the full file with the labelgate service, see Single Host → Tunnel.

Reaching your services

cloudflared opens the service URL itself, so the address must work from the cloudflared container.

Service runs...Use in serviceExtra setup
in the same Compose filehttp://app:80 (service name)none
in another Compose projecthttp://app:80put both containers on one shared network (below)
directly on the hosthttp://host.docker.internal:8080add extra_hosts to cloudflared (below)

Shared network for containers from other Compose projects:

services:
  cloudflared:
    networks: [tunnel]

networks:
  tunnel:
    name: tunnel # other projects join it with: networks: { tunnel: { external: true } }

A service on the host itself:

services:
  cloudflared:
    extra_hosts:
      - "host.docker.internal:host-gateway"

How to check it works

  • docker compose logs cloudflared shows Registered tunnel connection lines.
  • The tunnel shows Healthy in the Zero Trust dashboard.
  • The tunnel's hostname routes in the dashboard list the hostnames from your labels.
  • curl -I https://app.example.com answers from your app.

Common problems

SymptomFix
502 Bad Gatewaycloudflared cannot reach the service. Use the service name, not localhost, and check the networks.
Hostname gives Cloudflare error 1033cloudflared is not running or uses the token of another tunnel. The token must belong to LABELGATE_CLOUDFLARE_TUNNEL_ID.
Labelgate shows the route active, but cloudflared ignores itcloudflared runs with a local config.yml (a locally managed tunnel). Create the tunnel in the dashboard as above and run cloudflared with --token only.
Agent host: 502 for some requestsEach host that runs cloudflared for a tunnel gets a share of its traffic. Give every host its own tunnel; see Multi-Host.

On this page