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) pluscloudflare.account_id. cloudflaredruns for that tunnel. See cloudflared Setup.cloudflaredcan reach theserviceaddress. Labelgate never connects to it; cloudflared does. Forhttp://web:80, putweband 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.
| Property | Required | Default | Example | Meaning |
|---|---|---|---|---|
hostname | yes | - | app.example.com | Public hostname. |
service | yes | - | http://web:80 | Where cloudflared sends the traffic. See Service formats. |
path | no | - | ^/api/ | Only requests whose path matches this regular expression. |
tunnel | no | default tunnel | secondary | A name from cloudflare.tunnels, or a tunnel ID. Default: default_tunnel, else cloudflare.tunnel_id. |
cleanup | no | true | false | Remove the route and its DNS record when the container is gone. false keeps them. |
credential | no | auto | company | API token for the hostname's DNS record and Access app. |
access | no | - | team | Put 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
service | Use for |
|---|---|
http://host:port, https://host:port | Web apps |
ssh://host:port, rdp://host:port | SSH, Remote Desktop |
tcp://host:port, udp://host:port | Other TCP or UDP services |
unix:/path/to.sock, unix+tls:/path/to.sock | A Unix socket on the cloudflared host |
http_status:404 | A fixed HTTP status (100-599) |
hello_world | Cloudflare's test page |
bastion | Cloudflare bastion mode |
Origin settings
Set them as labelgate.tunnel.<name>.origin.<setting>. Leave a setting out to use cloudflared's default.
| Setting | Example | Meaning |
|---|---|---|
connect_timeout | 30s | Timeout for connecting to the service. |
tls_timeout | 10s | Timeout for the TLS handshake with the service. |
tcp_keepalive | 30s | TCP keep-alive interval. |
keep_alive_connections | 100 | Maximum idle connections kept open. |
keep_alive_timeout | 90s | How long an idle connection stays open. |
no_tls_verify | true | Accept any certificate from the service (e.g. self-signed). |
origin_server_name | app.internal | Hostname expected on the service's certificate. |
ca_pool | /certs/ca.pem | CA file cloudflared uses to check the service's certificate. |
http_host_header | app.internal | Host header sent to the service. |
no_happy_eyeballs | true | Turn off Happy Eyeballs (IPv4/IPv6 fallback). |
disable_chunked_encoding | true | Turn off chunked transfer encoding. |
proxy_type | socks | socks, 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.tunnelsPer-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
servicemust behttp,https,tcp,sshorrdp(orhello_world/http_status:). The host must be a public or private IP address, or be allowed in the agent'sserviceslist on the main instance. Loopback addresses, Unix sockets,udpandbastionare refused.