Labelgate

Tunnel Labels

Publish container services through Cloudflare Tunnel with labels.

Two labels publish a service through your tunnel:

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

Labelgate adds a route app.example.com → http://web:80 to the tunnel, and a DNS record that points app.example.com to the tunnel.

Before this works:

  • A tunnel is configured: cloudflare.tunnel_id (LABELGATE_CLOUDFLARE_TUNNEL_ID) plus cloudflare.account_id.
  • cloudflared runs for that tunnel. See cloudflared Setup.
  • cloudflared can reach the service address. Labelgate never connects to it; cloudflared does. For http://web:80, put web and cloudflared on the same Docker network.

Labels

Every label has the form labelgate.tunnel.<name>.<property>. The <name> is any name you choose; see The name part.

PropertyRequiredDefaultExampleMeaning
hostnameyes-app.example.comPublic hostname.
serviceyes-http://web:80Where cloudflared sends the traffic. See Service formats.
pathno-^/api/Only requests whose path matches this regular expression.
tunnelnodefault tunnelsecondaryA name from cloudflare.tunnels, or a tunnel ID. Default: default_tunnel, else cloudflare.tunnel_id.
cleanupnotruefalseRemove the route and its DNS record when the container is gone. false keeps them.
credentialnoautocompanyAPI token for the hostname's DNS record and Access app.
accessno-teamPut an Access policy in front of the hostname.
origin.<setting>no-origin.no_tls_verify: "true"Fine-tune the connection to the service. See Origin settings.

Service formats

serviceUse for
http://host:port, https://host:portWeb apps
ssh://host:port, rdp://host:portSSH, Remote Desktop
tcp://host:port, udp://host:portOther TCP or UDP services
unix:/path/to.sock, unix+tls:/path/to.sockA Unix socket on the cloudflared host
http_status:404A fixed HTTP status (100-599)
hello_worldCloudflare's test page
bastionCloudflare bastion mode

Origin settings

Set them as labelgate.tunnel.<name>.origin.<setting>. Leave a setting out to use cloudflared's default.

SettingExampleMeaning
connect_timeout30sTimeout for connecting to the service.
tls_timeout10sTimeout for the TLS handshake with the service.
tcp_keepalive30sTCP keep-alive interval.
keep_alive_connections100Maximum idle connections kept open.
keep_alive_timeout90sHow long an idle connection stays open.
no_tls_verifytrueAccept any certificate from the service (e.g. self-signed).
origin_server_nameapp.internalHostname expected on the service's certificate.
ca_pool/certs/ca.pemCA file cloudflared uses to check the service's certificate.
http_host_headerapp.internalHost header sent to the service.
no_happy_eyeballstrueTurn off Happy Eyeballs (IPv4/IPv6 fallback).
disable_chunked_encodingtrueTurn off chunked transfer encoding.
proxy_typesockssocks, or empty for none.

Times are whole seconds: 30s, 2m or just 30.

Recipes

Several routes on one container

labels:
  labelgate.tunnel.web.hostname: "www.example.com"
  labelgate.tunnel.web.service: "http://app:80"
  labelgate.tunnel.api.hostname: "api.example.com"
  labelgate.tunnel.api.service: "http://app:3000"

Split one hostname by path

labels:
  labelgate.tunnel.api.hostname: "example.com"
  labelgate.tunnel.api.service: "http://api:3000"
  labelgate.tunnel.api.path: "^/api/"
  labelgate.tunnel.site.hostname: "example.com"
  labelgate.tunnel.site.service: "http://site:80"

Requests to /api/... go to api. Everything else goes to site.

HTTPS service with a self-signed certificate

labels:
  labelgate.tunnel.nas.hostname: "nas.example.com"
  labelgate.tunnel.nas.service: "https://nas:5001"
  labelgate.tunnel.nas.origin.no_tls_verify: "true"

SSH

labels:
  labelgate.tunnel.ssh.hostname: "ssh.example.com"
  labelgate.tunnel.ssh.service: "ssh://dev-server:22"

Use another tunnel

labels:
  labelgate.tunnel.app.hostname: "internal.example.com"
  labelgate.tunnel.app.service: "http://internal:8080"
  labelgate.tunnel.app.tunnel: "secondary"   # a name from cloudflare.tunnels

Per-container defaults

labelgate.tunnel.default.<property> sets a default for every tunnel name in the same container. Allowed properties: tunnel, credential, cleanup.

labels:
  labelgate.tunnel.default.tunnel: "secondary"
  labelgate.tunnel.web.hostname: "app.example.com"
  labelgate.tunnel.web.service: "http://app:80"
  labelgate.tunnel.api.hostname: "api.example.com"
  labelgate.tunnel.api.service: "http://app:3000"

Good to know

  • Do not add a DNS label for a tunnel hostname. The tunnel creates its own DNS record, so a second one is a conflict.
  • Routes you added by hand in Cloudflare are kept. If one already uses the same hostname and path, your label gets conflict: existing record not owned by labelgate. See Ownership & Conflicts.
  • Containers on an agent are limited for safety. Their service must be http, https, tcp, ssh or rdp (or hello_world / http_status:). The host must be a public or private IP address, or be allowed in the agent's services list on the main instance. Loopback addresses, Unix sockets, udp and bastion are refused.

On this page