Labelgate

Single Host

Copy-paste Compose files for running Labelgate on one Docker host.

Use these recipes when all your containers run on one Docker host. For several hosts, see Multi-Host.

1. Create .env

Put this file next to your compose.yaml:

# Cloudflare API token (see Getting Started for the permissions)
LABELGATE_CLOUDFLARE_API_TOKEN=your-cloudflare-api-token
# Dashboard password. Generate with: openssl rand -hex 32
LABELGATE_API_TOKEN=paste-a-random-string
# Group that owns the Docker socket: stat -c '%g' /var/run/docker.sock
DOCKER_GID=999

# Only for the tunnel recipes:
LABELGATE_CLOUDFLARE_ACCOUNT_ID=your-account-id
LABELGATE_CLOUDFLARE_TUNNEL_ID=your-tunnel-id
TUNNEL_TOKEN=your-cloudflared-token

See Getting Started for how to create the API token, and cloudflared for the tunnel ID and token.

2. Pick a recipe

DNS records only

Points www.example.com at this host's public IP. No tunnel needed.

compose.yaml
services:
  labelgate:
    image: ghcr.io/channinghe/labelgate:v0.3
    restart: unless-stopped
    group_add: ["${DOCKER_GID}"]
    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

  web:
    image: nginx:alpine
    ports:
      - "80:80"
    labels:
      labelgate.dns.web.hostname: "www.example.com"
      # Defaults: type A, target auto (this host's public IP), proxied true

volumes:
  labelgate-data:

Tunnel (no open ports)

Publishes app.example.com through a Cloudflare Tunnel. Labelgate adds the route and the DNS record.

compose.yaml
services:
  labelgate:
    image: ghcr.io/channinghe/labelgate:v0.3
    restart: unless-stopped
    group_add: ["${DOCKER_GID}"]
    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

  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" # Compose service name, not localhost

volumes:
  labelgate-data:

Add a login page (Access)

Add this service to the tunnel recipe. Only @example.com email addresses can open admin.example.com.

  admin:
    image: nginx:alpine
    labels:
      labelgate.access.team.policy.include.emails_ending_in: "@example.com"
      labelgate.access.team.session_duration: "8h"
      labelgate.tunnel.admin.hostname: "admin.example.com"
      labelgate.tunnel.admin.service: "http://admin:80"
      labelgate.tunnel.admin.access: "team"

Your Cloudflare API token also needs Access: Apps and Policies: Edit. All Access labels are in Access labels.

Preview environments

Add one service per preview. When the container is removed, Labelgate deletes the route and DNS record after sync.remove_delay (LABELGATE_SYNC_REMOVE_DELAY, default 30m).

  preview:
    image: myapp:pr-${PR_NUMBER}
    labels:
      labelgate.tunnel.preview.hostname: "pr-${PR_NUMBER}.preview.example.com"
      labelgate.tunnel.preview.service: "http://preview:3000"

3. Start and check

docker compose up -d
docker compose logs -f labelgate
  • Logs: no level=WARN msg="reconcile problem" lines.
  • Dashboard: open http://127.0.0.1:28111 and sign in with LABELGATE_API_TOKEN. Every resource should be active.
  • DNS: dig +short www.example.com returns Cloudflare IPs (proxied records hide your real IP).
  • Tunnel: curl -I https://app.example.com answers from your app.

Common problems

SymptomFix
permission denied on /var/run/docker.sockDOCKER_GID is wrong. Run stat -c '%g' /var/run/docker.sock and put the number in .env.
Dashboard does not load; the log shows API and dashboard disabled: api.token is empty (WARN)LABELGATE_API_TOKEN is empty. Sync keeps running, but the API and the dashboard are off. Set the token and run docker compose up -d.
Labelgate exits at start with api.token (env LABELGATE_API_TOKEN): must be at least 16 charactersThe token is too short. Make a new one with openssl rand -hex 32 and run docker compose up -d.
Database cannot be written (bind mount like ./data:/app/config)Run sudo chown -R 65532:65532 ./data once. The named volume above needs nothing.
Tunnel shows 502 Bad Gatewayservice uses localhost or a container cloudflared cannot reach. Use the Compose service name and keep cloudflared on the same network as the app.
conflict: existing record not owned by labelgateA record for that hostname already exists. Delete it in Cloudflare, or pick another hostname. See Ownership.

On this page