Configuration
Configure Labelgate with environment variables, a config file, or both.
Labelgate reads its settings from three places. When a setting appears in more than one, the higher one wins:
- Environment variables (
LABELGATE_...) - A config file (YAML, JSON or TOML)
- Built-in defaults
Every key and its environment variable is listed in the Configuration Reference.
Environment variables only
This is the simplest setup and is enough for a single host.
services:
labelgate:
image: ghcr.io/channinghe/labelgate:v0.3
environment:
LABELGATE_CLOUDFLARE_API_TOKEN: ${CF_API_TOKEN}
LABELGATE_CLOUDFLARE_ACCOUNT_ID: ${CF_ACCOUNT_ID}
LABELGATE_CLOUDFLARE_TUNNEL_ID: ${CF_TUNNEL_ID}
LABELGATE_API_TOKEN: ${LABELGATE_API_TOKEN} # openssl rand -hex 32To get the variable name for a key: replace . with _, write it in upper case and add LABELGATE_. For example, sync.remove_delay becomes LABELGATE_SYNC_REMOVE_DELAY. Lists are comma-separated: LABELGATE_AGENT_ACCEPT_TUNNELS=default,secondary. An empty variable is ignored.
Config file
You need a file for these sections. They have no environment variables:
cloudflare.credentials: more than one Cloudflare API token.cloudflare.tunnels: more than one tunnel.agent.agents: named agents, each with its own token.
Labelgate uses the first file it finds:
- The path given with
-c/--config. - The path in
LABELGATE_CONFIG. labelgate.yaml(or.yml,.json,.toml) in the working directory (/appin the image)./etc/labelgate/labelgate.yaml(or.yml,.json,.toml).
In Docker, mount the file at /etc/labelgate/labelgate.yaml. A commented example is in configs/labelgate.example.yaml.
Both
Put the structure in the file and pass secrets as environment variables. The variables override the file.
The file is not templated: ${VAR} inside it stays as literal text. Pass secrets through environment variables, or write them into the file.
Minimal main config
labelgate.yaml:
cloudflare:
account_id: your-account-id
tunnel_id: your-tunnel-id
# Secrets come from the environment:
# LABELGATE_CLOUDFLARE_API_TOKEN, LABELGATE_API_TOKENdocker-compose.yaml:
services:
labelgate:
image: ghcr.io/channinghe/labelgate:v0.3
restart: unless-stopped
group_add:
- "999" # group of the Docker socket: stat -c '%g' /var/run/docker.sock
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./labelgate.yaml:/etc/labelgate/labelgate.yaml:ro
- ./labelgate-data:/app/config # database; sudo chown -R 65532:65532 ./labelgate-data
environment:
LABELGATE_CLOUDFLARE_API_TOKEN: ${CF_API_TOKEN}
LABELGATE_API_TOKEN: ${LABELGATE_API_TOKEN}
ports:
- "127.0.0.1:28111:28111" # dashboard and APIMinimal agent config
An agent runs on another Docker host and reports its containers to the main instance. It needs no Cloudflare token.
On the agent host:
services:
labelgate-agent:
image: ghcr.io/channinghe/labelgate:v0.3
restart: unless-stopped
group_add:
- "999" # group of the Docker socket: stat -c '%g' /var/run/docker.sock
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
LABELGATE_MODE: agent
LABELGATE_CONNECT_ENDPOINT: wss://main.example.com:28112/ws
LABELGATE_CONNECT_AGENT_ID: edge1 # must equal agent.agents.edge1 on the main
LABELGATE_CONNECT_TOKEN: ${AGENT_TOKEN} # openssl rand -hex 32This agent is listed under agent.agents.edge1 on the main (below), so LABELGATE_CONNECT_AGENT_ID must be edge1. The ID is optional only for agents that log in with agent.accept_token. Mount /etc/machine-id:/etc/machine-id:ro for those, so the ID stays the same when the container is recreated.
On the main instance, add the agent to labelgate.yaml with the same ID and token, and publish port 28112:
agent:
enabled: true
tls: # needed for wss://
cert: /app/config/tls/server.crt
key: /app/config/tls/server.key
agents:
edge1:
token: "<same value as AGENT_TOKEN>"By default this agent may use any hostname except wildcards (*.example.com), only the default tunnel, and only IP addresses in a tunnel service. If the main's certificate comes from a private CA, set LABELGATE_CONNECT_TLS_CA on the agent. See Multi-Host for allow-lists, inbound mode and TLS options.
Things to know
- Mistakes stop startup. Unknown keys and invalid values are errors. All problems are listed at once, so you can fix them in one go.
- Durations need a unit. Write
30s,5mor24h. A bare30is an error; write0sfor zero. - Restart to apply changes. The configuration is read once at startup.
SIGHUPdoes not reload it. - Old keys fail. Keys removed in v0.3 are errors. See Removed keys.
- Agents ignore main-only settings. In
mode: agent, onlylog_*,docker,retryandconnectare used.
Command line
labelgate [-c PATH] run (main or agent, from the configuration)
labelgate [-c PATH] healthcheck the container's health check
labelgate --version print the versionLabelgate exits with code 1 on a configuration error and prints the reason.