Self-host your gateway: one Docker command (gateway-server)

Deploy the open-source relay gateway & web console in one Docker container with SQLite WAL or PostgreSQL.

Docker quick start

The gateway-server source lives inside the plugin repository under gateway-server/ and runs as a non-root user (uid 100, gid 101).

Build and run with TCP + dual UDP ports
docker pull kyomio/zen-remote-gateway:latest

docker run -d --name zr-gateway \
  --restart unless-stopped \
  -p 19393:19393/tcp \
  -p 19393:19393/udp \
  -p 19394:19394/udp \
  -v zr-gateway-data:/data \
  -v $(pwd)/certs:/certs \
  kyomio/zen-remote-gateway:latest
Read the one-time initial admin password
docker logs zr-gateway
TCP reverse proxies do not forward UDP STUN packets. Expose 19393/udp and 19394/udp directly for NAT hole-punching.

Core environment variables

All environment variables are optional:

VariableDefaultDescription
ZR_GATEWAY_PORT19393Main port for TCP (console + WebSocket) and primary UDP STUN
ZR_GATEWAY_UDP_ALT_PORT+1 (19394)Auxiliary UDP port for NAT probing (0 disables and lowers hole-punch success; not recommended)
ZR_GATEWAY_PUBLIC_URLemptyExternal URL behind a reverse proxy; invite links are built from it
ZR_GATEWAY_DATA_DIR./data (/data in Docker)Directory for SQLite database and master.key
ZR_GATEWAY_DATABASE_URLemptyPostgreSQL connection URL (small deployments can stay on default SQLite WAL)
ZR_GATEWAY_ADMIN_USER / _PASSWORDadmin@local / randomInitial admin credentials (unset password generates a one-time 16-char password on first boot of an empty database)
ZR_GATEWAY_ALLOW_SIGNUPfalseEnable self-service sign-up (can also be toggled in the console)
ZR_GATEWAY_MAX_PEERS8Default peer limit for new networks (2–64)
ZR_GATEWAY_RELAY_RATE_KBPS4096Per-peer relay bandwidth limit in KB/s (direct traffic is unthrottled)
ZR_GATEWAY_MAX_NETWORKS_PER_USER3Max networks per user in the default group (1–50; adjustable per group in console)
ZR_GATEWAY_CERT_DIR./certs (/certs in Docker)TLS certificate directory (fullchain.pem / privkey.pem, or PEM files selected in console)
ZR_GATEWAY_AUTO_UPDATEtrueInitial auto-update setting written only on first boot; manage via the console afterwards

Production ops: TLS & reverse proxy

The gateway supports single-port TLS: 19393/tcp serves HTTP and HTTPS/WSS on the same port with no Nginx/Caddy required. Supply certificates by mounting /certs (auto-enabled on first boot if valid fullchain.pem + privkey.pem exist) or uploading PEM files in TLS & Certificates inside the admin console.

  • Sharing port 443: disable built-in TLS, place Nginx or Caddy in front, and set ZR_GATEWAY_PUBLIC_URL to your public https:// URL; keep UDP 19393/19394 exposed directly.
  • WebSocket upgrades: nodes connect over /peer/v1/ws, so your proxy must pass Upgrade and Connection "upgrade" headers.
  • Strict certificate verification: nodes always validate certificate chains and hostnames and never downgrade to plaintext on failure.
  • Explicit transport flags: bare HTTP entries lack control-plane TLS (session payloads remain end-to-end encrypted); invite links append ?tls=0|1 whenever transport differs from the host default.
  • Certificate rotation: upload a new certificate in the console (or replace files in /certs) and click Reload; behind a proxy, rotate at the proxy layer.
  • Verify certs: run openssl s_client -connect <host>:19393 -servername <host> </dev/null | openssl x509 -noout -fingerprint -sha256 -enddate (or port 443 behind a proxy).

Production ops: data & backup

  • All persistent state lives in the data directory (/data inside Docker): the SQLite database and master.key (0600, generated on first boot).
  • Cold backup: stop the service and copy the entire data directory; losing master.key invalidates all existing credentials, so always back it up together with the database.
  • PostgreSQL mode: when ZR_GATEWAY_DATABASE_URL is set, your PostgreSQL backup routine covers the database while master.key stays in the data directory.
  • Directory ownership: the container runs as non-root (zr, uid 100:gid 101); on Linux hosts run chown 100:101 ./data before bind-mounting.

Production ops: upgrade & rollback

  • Automatic hot updates: checks for bundles 30 s after startup and every 12 h thereafter, switching /data/releases after two idle checks 5 s apart.
  • Auto-rollback protection: if a hot-updated bundle fails its health check within 15 seconds, the gateway rolls back automatically; manual check and apply controls live in the admin console.
  • Setting precedence: ZR_GATEWAY_AUTO_UPDATE=false applies only on first boot before the setting exists in the database; toggle existing instances from the admin console.
  • Image upgrades: when native dependencies or the Node major version change, the console displays docker compose pull && docker compose up -d; back up first and keep /data intact.
  • Rollback & mixed versions: roll back by restarting with the previous image tag. During mixed-version rollouts, missing relay counts or status fields do not mean a link failure.
  • Shutdown grace period: on SIGTERM/SIGINT, the gateway stops intake and flushes final traffic counts and status (~5 s default); set container stop grace period to ≥15 seconds.