Tera Router
Getting Started

Docker Compose

Deploy the Tera Router API server and dashboard as a single container with Docker Compose.

The release image at ghcr.io/montara-project/tera-router bundles the API server and the built dashboard in one container — the server serves the dashboard on the same port, so the UI and the gateway share a single origin. The SQLite database lives on a named volume and survives image upgrades.

Prerequisites

  • Docker with the Compose plugin.
  • A machine reachable from your browser (directly or behind a reverse proxy).

1. Get the compose file

The repository ships a ready-made deploy/docker-compose.yaml: one app service — the API server serving the built dashboard on the same port — plus an optional Headroom sidecar behind a profile. Every server flag falls back to its environment variable, so the file needs no command: list; the environment: block below is the whole configuration.

services:
  app:
    image: ghcr.io/montara-project/tera-router:v1.23.0
    restart: unless-stopped
    # APP_PORT is the host port; the container always listens on 8080.
    ports:
      - '${APP_PORT:-8080}:8080'
    environment:
      ENV: ${APP_ENV:-production}
      MACHINE_ID: ${APP_MACHINE_ID:?APP_MACHINE_ID is required}
      APP_SECRET: ${APP_SECRET:?APP_SECRET is required}
      DEBUG: ${APP_DEBUG:-false}
      ADMIN_EMAIL: ${APP_ADMIN_EMAIL:-admin@tera.local}
      ADMIN_PASSWORD: ${APP_ADMIN_PASSWORD:?APP_ADMIN_PASSWORD is required}
      APP_NAME: ${APP_NAME:-tera-router-server}
      CORS_ALLOWED_ORIGINS: ${APP_CORS_ALLOWED_ORIGINS:-*}
      RATE_LIMIT_EXEMPT_IPS: ${RATE_LIMIT_EXEMPT_IPS:-}
      TRUSTED_PROXIES: ${TRUSTED_PROXIES:-}
      # Injected into the served web UI at runtime; set only when the API
      # lives on a different origin than the dashboard.
      API_URL: ${API_URL:-}
      DATABASE_PATH: /app/data/terarouter.db
      MIGRATE_ON_BOOT: 'true'
      SEED_ON_BOOT: ${SEED_ON_BOOT:-true}
      SENTRY_DSN: ${SENTRY_DSN:-}
      # Dashboard SSO via any OIDC provider (Pocket ID, Keycloak, …).
      OIDC_ISSUER: ${OIDC_ISSUER:-}
      OIDC_CLIENT_ID: ${OIDC_CLIENT_ID:-}
      OIDC_CLIENT_SECRET: ${OIDC_CLIENT_SECRET:-}
      OIDC_PROVIDER_NAME: ${OIDC_PROVIDER_NAME:-}
      OIDC_REDIRECT_URL: ${OIDC_REDIRECT_URL:-}
      HEADROOM_URL: ${HEADROOM_URL:-http://headroom:8787}
      HEADROOM_PROXY_TOKEN: ${HEADROOM_PROXY_TOKEN:-}
    healthcheck:
      test: ['CMD', 'wget', '-qO-', 'http://127.0.0.1:8080/health', '||', 'exit', '1']
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 10s
    volumes:
      - tera-data:/app/data
    depends_on:
      headroom:
        condition: service_started
        required: false

  # Opt in with `docker compose --profile headroom up` and a shared
  # HEADROOM_PROXY_TOKEN.
  headroom:
    image: ghcr.io/headroomlabs-ai/headroom:${HEADROOM_VERSION:-0.41.0}
    profiles: [headroom]
    restart: unless-stopped
    environment:
      HEADROOM_HOST: '0.0.0.0'
      HEADROOM_PORT: '8787'
      HEADROOM_COMPRESS_ALLOW_REMOTE: '1'
      HEADROOM_PROXY_TOKEN: ${HEADROOM_PROXY_TOKEN:-}
      HEADROOM_DISABLE_KOMPRESS: ${HEADROOM_DISABLE_KOMPRESS:-1}
      HEADROOM_DISABLE_KOMPRESS_FALLBACK: ${HEADROOM_DISABLE_KOMPRESS_FALLBACK:-1}

volumes:
  tera-data:

Two ways to run it:

  • From a repo checkout — docker compose -f deploy/docker-compose.yaml up -d pulls the pinned release image and starts the stack; it does not build deploy/Dockerfile, so local changes are not deployed. For a local build run docker build -f deploy/Dockerfile -t tera-router:local . from the repo root and set image: to tera-router:local.
  • Standalone — copy the file, keep image: on the release tag you want (or bump it, e.g. ghcr.io/montara-project/tera-router:v1.22.0), and run the stack from the directory that holds the copy.

Env-only config needs a current image

Reading configuration from the environment alone lands in the release that follows v1.22.0. To pin v1.22.0 today, keep the same environment: block but add a command: that forwards the values as flags (--machine-id, --app-secret, …) — names match the env vars kebab-cased.

2. Create .env

Place it next to the compose file (deploy/.env when running from the repo) and fill in the values:

# Required — Compose refuses to interpolate without them
APP_MACHINE_ID=1
APP_SECRET=generate_from_openssl_rand_base64_48
APP_ADMIN_PASSWORD=your_password

# Seeded admin account
APP_ADMIN_EMAIL=your@email.com

# App
APP_ENV=production
APP_DEBUG=false
APP_PORT=8080
APP_NAME=tera-router-server
APP_CORS_ALLOWED_ORIGINS=*

# Client IPs that bypass the dashboard rate limit (comma-separated)
RATE_LIMIT_EXEMPT_IPS=
# Proxies trusted to supply X-Forwarded-For (comma-separated IPs/CIDRs)
TRUSTED_PROXIES=

# Only when the API lives on another origin than the dashboard
API_URL=

# Run baseline seeders on boot (roles, admin, Default plan)
SEED_ON_BOOT=true
SENTRY_DSN=

# Dashboard SSO via an OIDC provider (Pocket ID, Keycloak, …); the login
# button appears only when issuer + client id + secret are all set
OIDC_ISSUER=
OIDC_CLIENT_ID=
OIDC_CLIENT_SECRET=
OIDC_PROVIDER_NAME=Pocket ID
OIDC_REDIRECT_URL=

# Headroom sidecar (--profile headroom)
HEADROOM_PROXY_TOKEN=
HEADROOM_VERSION=0.41.0

APP_SECRET is the house key

APP_SECRET signs session tokens and derives the key that encrypts stored provider credentials. Compose refuses to start without it. Use at least 32 random characters (openssl rand -base64 48); the server warns at boot about a shorter one. Changing it later makes every stored credential unreadable — set it once and keep it safe.

3. Start the stack

# From a repo checkout:
docker compose -f deploy/docker-compose.yaml up -d
docker compose -f deploy/docker-compose.yaml logs -f app

# Standalone, from the directory holding the copied file:
docker compose up -d
docker compose logs -f app

On boot the container:

  1. Runs pending SQLite migrations (MIGRATE_ON_BOOT).
  2. Seeds baseline data (SEED_ON_BOOT) — roles, the admin user from ADMIN_EMAIL/ADMIN_PASSWORD, and the Default plan.
  3. Opens the gateway (/v1/*), the dashboard API, and the dashboard UI on the same port (APP_PORT, default 8080).

Compose reports healthy once the built-in healthcheck passes (wget http://127.0.0.1:8080/health inside the container). Then open https://yourdomain.com (or http://<host>:8080 directly) and sign in with the seeded admin account.

Production notes

  • Trusted proxies — TRUSTED_PROXIES must match the subnet your reverse proxy or load balancer actually sits in, so the server reads real client IPs for rate limiting and logs. Adjust the value before deploying. Behind Cloudflare and Traefik, see below.
  • IP blocking — Settings → Security → Blocked IPs refuses addresses or CIDR ranges with 403, and an address with 10 failed sign-ins in 15 minutes is blocked for 15 minutes. Both key on the client IP, so set trusted proxies first: otherwise every visitor shares the proxy's address and one attacker's failed sign-ins block everyone.
  • Rate-limit exemptions — RATE_LIMIT_EXEMPT_IPS takes a comma-separated list of IPs that bypass the dashboard rate limit (e.g. an internal monitoring host).
  • Token saving (optional) — the repo's deploy/docker-compose.yaml ships a Headroom sidecar behind the headroom profile: docker compose --profile headroom up -d with a shared HEADROOM_PROXY_TOKEN (openssl rand -hex 32). The server reaches it at HEADROOM_URL (http://headroom:8787); switch it on in Settings → Token Saving.
  • Persistence — everything stateful is the SQLite file at /app/data/terarouter.db on the tera-data volume. Include it in your backup routine.
  • Upgrades — bump the image tag, then docker compose up -d. Pending migrations apply on boot while MIGRATE_ON_BOOT=true; pinning the tag keeps the dashboard bundle and server binary in sync.

Behind Cloudflare and Traefik (Dokploy)

When requests travel client → Cloudflare → Traefik → container, two hops sit in front of the server. Traefik drops any X-Forwarded-For that arrives from an address it does not trust and writes the Cloudflare edge IP instead, so every visitor looks like Cloudflare. Trust both hops:

  1. Traefik trusts Cloudflare. In Dokploy's Traefik config (usually /etc/dokploy/traefik/traefik.yml), add Cloudflare's ranges to both entrypoints, then restart Traefik. Check the list against cloudflare.com/ips since it can change.

    traefik.yml
    entryPoints:
      web:
        address: ':80'
        forwardedHeaders:
          trustedIPs: &cloudflare
            - 173.245.48.0/20
            - 103.21.244.0/22
            - 103.22.200.0/22
            - 103.31.4.0/22
            - 141.101.64.0/18
            - 108.162.192.0/18
            - 190.93.240.0/20
            - 188.114.96.0/20
            - 197.234.240.0/22
            - 198.41.128.0/17
            - 162.158.0.0/15
            - 104.16.0.0/13
            - 104.24.0.0/14
            - 172.64.0.0/13
            - 131.0.72.0/22
            - 2400:cb00::/32
            - 2606:4700::/32
            - 2803:f800::/32
            - 2405:b500::/32
            - 2405:8100::/32
            - 2a06:98c0::/29
            - 2c0f:f248::/32
      websecure:
        address: ':443'
        forwardedHeaders:
          trustedIPs: *cloudflare

    Only the forwardedHeaders blocks are new: merge them into Dokploy's existing entrypoints and keep everything else (providers, TLS, certificatesResolvers) as it is. Traefik now forwards X-Forwarded-For: <client>, <cloudflare-edge>.

  2. tera-router trusts Traefik and Cloudflare. Set TRUSTED_PROXIES to the Docker network Traefik runs on plus the same Cloudflare ranges, comma-separated:

    docker network inspect dokploy-network --format '{{(index .IPAM.Config 0).Subnet}}'
    .env
    TRUSTED_PROXIES=10.0.1.0/24,173.245.48.0/20,103.21.244.0/22,...,2c0f:f248::/32

    Without the Traefik subnet the header is ignored (the direct peer is Traefik). Without the Cloudflare ranges the server stops at the edge IP and reports it as the client.

The server reads X-Forwarded-For right to left and returns the first address that is not a trusted proxy, so entries a client forges on the left are skipped. A request that bypasses Cloudflare and hits the origin directly comes from an untrusted address: Traefik discards its forwarded headers and the server sees the caller's real IP. Do not switch to CF-Connecting-IP: Traefik passes it through untouched, so anyone reaching the origin directly could forge it. Optionally, firewall ports 80/443 to Cloudflare's ranges so the origin cannot be reached around Cloudflare at all.

To verify, fail a sign-in from another network (e.g. a phone on mobile data) and check Settings → Security: the recorded address should be the phone's, not a Cloudflare or 10.x address.

Next steps

  • Configuration — full reference of the environment variables used above.
  • Remote access — the image bundles cloudflared for the one-click Cloudflare tunnel; Tailscale runs on the Docker host.
  • Dashboard tour — get to know each page.
  • Gateway API — your first request through the router.

On this page