Getting Started
Run Labelgate with Docker Compose and publish your first app through a Cloudflare Tunnel.
This page takes you from nothing to https://app.example.com served through a Cloudflare Tunnel.
You need:
- Docker with Docker Compose;
- a domain on Cloudflare;
- a Cloudflare Tunnel. Create one under Zero Trust > Networks > Tunnels and note its tunnel ID and token.
1. Create a Cloudflare API token
Create a custom token at My Profile > API Tokens with these permissions:
| You want | Permissions |
|---|---|
| DNS only | Zone:Zone:Read, Zone:DNS:Edit |
| DNS + Tunnel | the above + Account:Cloudflare Tunnel:Edit |
| DNS + Tunnel + Access | the above + Access: Apps and Policies:Edit |
- Zone Resources: the domains Labelgate may manage, or "All zones".
- Account Resources: the account that owns the tunnel.
Your account ID is shown on any domain's overview page in the Cloudflare dashboard.
2. Create .env
LABELGATE_CLOUDFLARE_API_TOKEN=your-api-token
LABELGATE_CLOUDFLARE_ACCOUNT_ID=your-account-id
LABELGATE_CLOUDFLARE_TUNNEL_ID=your-tunnel-id
# Dashboard and API login. Without it both are off.
# Generate with: openssl rand -hex 32
LABELGATE_API_TOKEN=a-long-random-string
# For cloudflared, not for Labelgate
TUNNEL_TOKEN=your-tunnel-tokenKeep this file out of version control.
3. Create compose.yaml
Labelgate runs as user 65532. Before you start, run these two commands:
stat -c '%g' /var/run/docker.sock # group ID for group_add below
mkdir -p labelgate-data && sudo chown -R 65532:65532 labelgate-dataservices:
labelgate:
image: ghcr.io/channinghe/labelgate:v0.3
restart: unless-stopped
group_add:
- "REPLACE_WITH_GROUP_ID" # output of the stat command
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./labelgate-data:/app/config
environment:
- LABELGATE_CLOUDFLARE_API_TOKEN
- LABELGATE_CLOUDFLARE_ACCOUNT_ID
- LABELGATE_CLOUDFLARE_TUNNEL_ID
- LABELGATE_API_TOKEN
ports:
- "127.0.0.1:28111:28111" # dashboard and API, local only
cloudflared:
image: cloudflare/cloudflared:latest
restart: unless-stopped
command: tunnel run --token ${TUNNEL_TOKEN}
networks:
- cloudflared-network
webapp:
image: nginx:alpine
container_name: webapp
labels:
labelgate.tunnel.web.hostname: "app.example.com"
labelgate.tunnel.web.service: "http://webapp:80"
networks:
- cloudflared-network
networks:
cloudflared-network:
name: cloudflared-networkLabelgate itself does not need to join cloudflared-network. It only talks to the Cloudflare API. The network lets cloudflared reach your apps by container name, without published ports.
4. Start it
docker compose up -dWithin a few seconds Labelgate adds a tunnel rule and a DNS record for app.example.com. Open https://app.example.com and you should see the nginx welcome page.
To see what Labelgate manages, open http://localhost:28111/dashboard/ and sign in with your LABELGATE_API_TOKEN. To see errors, run docker compose logs labelgate.
If app.example.com already exists on Cloudflare, Labelgate does not overwrite it. It shows a conflict error instead. See Ownership & Conflicts.
When a container is removed, Labelgate deletes its Cloudflare resources 30 minutes later. To keep them, add labelgate.tunnel.web.cleanup: "false".
Apps in other Compose projects
Join the same network and add labels:
services:
other-app:
image: nginx:alpine
container_name: other-app
labels:
labelgate.tunnel.other.hostname: "other.example.com"
labelgate.tunnel.other.service: "http://other-app:80"
networks:
- cloudflared-network
networks:
cloudflared-network:
external: trueDNS only (no tunnel)
If you only want DNS records, you need neither cloudflared nor the tunnel settings:
services:
labelgate:
image: ghcr.io/channinghe/labelgate:v0.3
restart: unless-stopped
group_add:
- "REPLACE_WITH_GROUP_ID"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./labelgate-data:/app/config
environment:
- LABELGATE_CLOUDFLARE_API_TOKEN
- LABELGATE_API_TOKEN
ports:
- "127.0.0.1:28111:28111" # dashboard and API, local only
myapp:
image: nginx:alpine
labels:
labelgate.dns.web.hostname: "app.example.com"
labelgate.dns.web.type: "A"
labelgate.dns.web.target: "203.0.113.1"
labelgate.dns.web.proxied: "true"Next steps
- Label Reference: every DNS, Tunnel and Access label.
- Configuration: config files and more settings.
- Examples: more setups, including several hosts.
- Upgrading to v0.3: coming from v0.2.