Deployment, Configuration & Backups
Deploy Cockpit Context in production with Docker Compose, reverse proxies, Cloudflare Tunnel, environment tuning, and verified Postgres backups.
Cockpit Context deploys on a Linux host with Docker Compose: one Node.js 26.13.1 application container (app) and one PostgreSQL 18 (postgres:18.6-trixie) container.
Single-Replica Constraint & Network Topology
- Run exactly one
appreplica, using stop-first replacement during upgrades. In-process job execution, rate limiters, SSE live streams, and answer/version caches are process-local. Never scaleapphorizontally or run two app instances against the same database simultaneously. - Network isolation:
compose.yamlpublishes no host ports. PostgreSQL runs exclusively on the Compose project-privateinternalnetwork under aliascockpit-context-postgres. Onlyappjoins bothinternalandegress(outbound HTTPS/SSH for OpenRouter, Git hosts, and optional SMTP/S3/OIDC). - Unique project name: Always pass a unique Compose project name (such as
-p cockpit-context) when sharing a host with other FlyCockpit services. Do not addcontainer_nameor global network/volume overrides.
Production Deployment
Clone the repository and prepare .env privately (never use .env.docker.defaults in production):
git clone https://github.com/FlyCockpit/context.git
cd context
cp .env.example .env
Generate strong secrets (pnpm generate:secrets, or openssl rand -hex 32 for POSTGRES_PASSWORD and openssl rand -base64 32 for COCKPIT_CONTEXT_ENCRYPTION_KEYS). Use a hex POSTGRES_PASSWORD because compose.yaml interpolates it directly into DATABASE_URL without URL-escaping.
Note:
compose.yamlbuildsDockerfilelocally by default. Release images are published toghcr.io/flycockpit/context:<version>by the manual Release workflow; pin by digest for immutable deployments and keep theappand optionalbackupimage tags identical.
First Administrator Bootstrap
You must set ADMIN_EMAILS before first boot. Until the first account exists, only the bootstrap flow can create an account (even if SIGNUP_ENABLED=true):
- Start the stack privately before routing public traffic. On startup, the server prints a one-time, in-memory
[bootstrap]token to stdout:docker compose -p cockpit-context logs app | grep '\[bootstrap\]' - Complete first signup privately. On a plain VPS, temporarily set
BETTER_AUTH_URL=https://localhost:8443,COCKPIT_CONTEXT_HTTP_PORT=3036, andTRUST_PROXY_HOPS=1, start with the loopback overlay:
Proxydocker compose -p cockpit-context -f compose.yaml -f compose.vps.yaml up -d --buildhttps://localhost:8443to127.0.0.1:3036with a loopback Caddy listener (tls internal), forward port8443over SSH (ssh -N -L 8443:127.0.0.1:8443 deploy@your-server), and visithttps://localhost:8443/en-US/signupwith yourADMIN_EMAILSaddress and[bootstrap]token. - Enroll administrator 2FA within the 24-hour grace period and save recovery codes.
- Stop the app, set
BETTER_AUTH_URLto your final public HTTPS origin, remove the temporary listener, configure public TLS routing, and start the app again.
Warning: If you plan to enable
FORCE_SSO=true, leave it unset during bootstrap. Create the administrator first, configure OIDC SSO, sign in once via SSO as that admin (matching verified email) so Better Auth links the identity, and only then enableFORCE_SSO=true.
If an existing database has users but no administrator, promote one directly in PostgreSQL (using lowercase email):
docker compose -p cockpit-context exec postgres psql -U cockpit_context -d cockpit_context \
-c "UPDATE \"user\" SET role = 'admin' WHERE email = 'you@example.com';"
Reverse Proxy, Dokploy & Cloudflare Tunnel
Every reverse proxy in front of Cockpit Context must satisfy four requirements:
- Exact
BETTER_AUTH_URL: SetBETTER_AUTH_URLto the exact public HTTPS origin (no trailing path). OAuth issuer (<origin>/api/auth), resource (<origin>/mcp), and cookies all derive from it. - Unbuffered SSE streaming on
/mcpand live views: Do not buffertext/event-streamresponses. Cockpit Context emits: keepalivecomments every 15 seconds, and MCP calls can stay open for up toCOCKPIT_CONTEXT_MCP_WAIT_SECONDS(900 seconds by default). - Preserve paths: Forward
/mcp,/api/auth/*, and/.well-known/*unchanged. - Accurate
TRUST_PROXY_HOPS: Defaults to0(ignoresX-Forwarded-For). Set1behind a single proxy (Traefik/Dokploy, Caddy, or a Cloudflare Tunnel directly toapp), or2for a Cloudflare Tunnel feeding Traefik/Caddy. Always restrict direct origin access to your proxy chain.
Plain VPS with Caddy
Set COCKPIT_CONTEXT_HTTP_PORT=3036 (avoiding port 3000 if Dokploy uses it) and launch with compose.vps.yaml:
docker compose -p cockpit-context -f compose.yaml -f compose.vps.yaml up -d --build
Configure Caddy with flush_interval -1 so SSE streams flush immediately:
context.example.com {
reverse_proxy 127.0.0.1:3036 {
flush_interval -1
}
}
Dokploy Compose
Create a Dokploy Compose project (not Swarm Application) using compose.yaml alone:
- Git source: Connect
https://github.com/FlyCockpit/context.gitwith Compose pathcompose.yamland put secrets/variables in the Environment tab. - Raw Compose file: Pin the app build context to a full commit SHA and pass
BUILDKIT_CONTEXT_KEEP_GIT_DIR: "1"so/readyreports the baked commit SHA. - In Dokploy’s Domains tab, route your HTTPS domain to service
app, container port3000. - Set
TRUST_PROXY_HOPS=1in the Compose environment (without it, every client shares Traefik’s IP for rate limits). - Compression: Cockpit Context ships no Node compression middleware. Attach a Traefik compress middleware (
traefik.http.middlewares.<name>.compress=true) to the router, and confirm SSE streams remain unbuffered.
Home Server Behind Cloudflare Tunnel
For servers behind NAT/CGNAT without a public IP, run a named cloudflared tunnel:
- Tunnel → app (
http://127.0.0.1:3036withcompose.vps.yaml, orcloudflaredcontainer on theegressnetwork pointing athttp://app:3000): setTRUST_PROXY_HOPS=1. - Tunnel → Traefik/Caddy → app: set
TRUST_PROXY_HOPS=2and addcloudflared’s IP to your proxy’s trusted proxy list. Serve the local proxy on plain HTTP (no HTTPS redirect loop). - For locally managed tunnel containers (
cloudflare/cloudflared, UID65532), store credentials outside the Git checkout (e.g./etc/cloudflared) withchmod 700on the directory,chmod 400on the JSON file, andchown -R 65532:65532 /etc/cloudflared. - Do not place Cloudflare Bot Fight Mode, Managed Challenges, or Cloudflare Access in front of
/mcp,/.well-known/*, or/api/auth/*—coding agents cannot solve browser challenges.
Runtime Health & Deploy Verification
- Liveness:
GET /health - Readiness (including migrations and baked commit):
GET /ready - Remote verification:
pnpm deploy:check https://context.example.com --commit <sha> - Host verification:
pnpm dokploy:verify --project cockpit-context --url https://context.example.com --commit <sha>
Environment Variables Reference
Core Required Settings
| Variable | Default | Description |
|---|---|---|
POSTGRES_PASSWORD |
(required) | Strong hex password (openssl rand -hex 32), interpolated into DATABASE_URL by compose.yaml. |
BETTER_AUTH_SECRET |
(required) | Random secret (≥ 32 chars) for sessions, OAuth signing, and password peppering. |
BETTER_AUTH_SECRET_PREVIOUS |
(unset) | Prior auth secret during zero-loss password pepper rotation. |
BETTER_AUTH_URL |
(required) | Exact public HTTPS origin (https://context.example.com), no path or trailing slash. |
ADMIN_EMAILS |
(required) | Comma-separated bootstrap admin email allowlist. Keep configured after first boot. |
COCKPIT_CONTEXT_ENCRYPTION_KEYS |
(required) | AES-256-GCM keyring (v1:<base64 32-byte key>) for saved SSH keys. |
OPENROUTER_API_KEY |
(unset) | OpenRouter API key. App boots without it, but investigations fail until set. |
COCKPIT_CONTEXT_MODEL |
(unset) | Primary OpenRouter model ID (required when OPENROUTER_API_KEY is set). |
COCKPIT_CONTEXT_HELPER_MODEL |
(unset) | Optional model ID for delegated exploration helper runs. |
Networking, Auth & Privacy
| Variable | Default | Description |
|---|---|---|
TRUST_PROXY_HOPS |
0 |
Exact number of trusted reverse proxies (1 for Traefik/Caddy/direct tunnel, 2 for tunnel + proxy). |
COCKPIT_CONTEXT_HTTP_PORT |
3000 |
Loopback port used only by compose.vps.yaml. |
CORS_ORIGIN |
(unset) | Leave unset for same-origin deploys; never wildcard. |
SIGNUP_ENABLED |
false |
Keep false and invite users from Admin → Users. |
SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, SMTP_FROM |
(unset) | Enables email verification, password resets, and emailed invites (587 STARTTLS or 465 implicit TLS). |
SSO_ENABLED, SSO_CLIENT_ID, SSO_CLIENT_SECRET, SSO_ISSUER, SSO_PROVIDER_NAME |
(unset) | Optional OIDC SSO configuration. |
FORCE_SSO |
false |
Disables password login; requires full SSO configuration in production. |
COCKPIT_CONTEXT_CONVERSATION_RETENTION_DAYS |
90 |
Days of inactivity before automatic conversation deletion (0 disables). |
COCKPIT_CONTEXT_OPERATOR_NAME, COCKPIT_CONTEXT_OPERATOR_CONTACT_EMAIL |
(unset) | Public operator details displayed on the privacy notice. |
COCKPIT_CONTEXT_GIT_HOST_ALLOWLIST |
(unset) | Comma-separated exact FQDNs of internal Git servers permitted to resolve to private IPs. |
Investigation Engine, Storage, LSP & Caching
| Variable | Default | Description |
|---|---|---|
COCKPIT_CONTEXT_DATA_DIR |
/data |
Persistent storage path for bare clones and checkouts. |
COCKPIT_CONTEXT_MAX_STORAGE_GB |
20 |
Decimal GB (10^9 bytes/GB) cache ceiling before LRU pruning to 90%. |
COCKPIT_CONTEXT_MODEL_API |
chat-completions |
Upstream API wire format: chat-completions, responses, or messages. |
COCKPIT_CONTEXT_OPENROUTER_BASE_URL |
https://openrouter.ai/api/v1 |
OpenRouter-compatible API root (HTTPS required in production). |
COCKPIT_CONTEXT_MAX_ITERATIONS |
100 |
Agent loop iteration cap per main investigation. |
COCKPIT_CONTEXT_RUN_TIMEOUT_SECONDS |
600 |
Wall-clock run cap and checkout lease length. |
COCKPIT_CONTEXT_MODEL_STALL_SECONDS |
90 |
Max silence per model call (10–3600). |
COCKPIT_CONTEXT_MAX_CONCURRENT_RUNS |
4 |
Global concurrent runs across all users. |
COCKPIT_CONTEXT_MAX_CONCURRENT_RUNS_PER_USER |
3 |
Concurrent main runs per user (overview summaries count globally only). |
COCKPIT_CONTEXT_MAX_QUEUED_RUNS_PER_USER |
20 |
Max queued main runs per user before returning BUSY (0 = unlimited). |
COCKPIT_CONTEXT_MAX_PARALLEL_HELPERS / COCKPIT_CONTEXT_MAX_HELPERS |
5 / 10 |
Parallel and total helper runs per investigation. |
COCKPIT_CONTEXT_MCP_WAIT_SECONDS |
900 |
Default and max wait_seconds for query_dependency / get_query_result. |
COCKPIT_CONTEXT_MCP_QUERIES_PER_HOUR |
30 |
Hourly query_dependency cap per MCP credential. |
COCKPIT_CONTEXT_MCP_QUERIES_PER_USER_PER_HOUR |
120 |
Aggregate hourly query_dependency cap across all of a user’s credentials (0 = off). |
COCKPIT_CONTEXT_MCP_TOOL_CALLS_PER_MINUTE |
120 |
Per-credential MCP tool call rate limit. |
COCKPIT_CONTEXT_MAX_MCP_RESULT_WAITS_PER_USER |
10 |
Concurrent parked get_query_result waits per user. |
COCKPIT_CONTEXT_MAX_LIVE_STREAMS_PER_USER |
20 |
Concurrent web SSE live streams per user. |
COCKPIT_CONTEXT_ANSWER_CACHE_ENABLED / _TTL_SECONDS / _MAX_ENTRIES |
true / 3600 / 500 |
Per-user in-memory MCP answer reuse settings. |
COCKPIT_CONTEXT_VERSION_CACHE_TTL_SECONDS / _MAX_ENTRIES |
300 / 1000 |
Exact version/tag/SHA resolution cache (0 = off). |
COCKPIT_CONTEXT_FETCH_INTERVAL_SECONDS |
300 |
Minimum interval between automatic branch remote fetches. |
COCKPIT_CONTEXT_LSP_SANDBOX |
required |
required (Landlock confinement; disables LSP if unavailable) or off (dev only). |
COCKPIT_CONTEXT_LSP_MAX_SERVERS / _IDLE_SECONDS |
4 / 30 |
Active language server pool size (0 disables LSPs) and idle eviction timeout. |
MIGRATE_ON_START |
true |
Apply committed migrations on boot (false only when running a separate migrate command first). |
DATABASE_POOL_MAX |
10 |
Postgres pool size (minimum 3 for auth lock slots). |
JOBS_CONCURRENCY |
2 |
In-process background job concurrency. |
Backup & Freshness Monitoring
| Variable | Default | Description |
|---|---|---|
BACKUP_ENABLED |
false |
Strict true/false. When true, migrating starts require a valid destination (/backups or S3) and take pre-migration and pre-drop dumps. |
BACKUP_SCHEDULE |
off |
Set daily with Compose profile backup to run scheduled dumps. |
BACKUP_HOUR_UTC / BACKUP_KEEP |
3 / 14 |
Daily dump UTC hour and local retention count. |
BACKUP_S3_BUCKET, BACKUP_S3_ACCESS_KEY_ID, BACKUP_S3_SECRET_ACCESS_KEY |
(unset) | Off-site S3 bucket and dedicated write credentials (unset by PID 1 entrypoint before tini execs the server). |
BACKUP_S3_REGION, BACKUP_S3_ENDPOINT, BACKUP_S3_PREFIX |
auto, (unset), cockpit-context/prod/database |
S3-compatible endpoint, region, and object key prefix. |
BACKUP_MONITOR_S3_ACCESS_KEY_ID, BACKUP_MONITOR_S3_SECRET_ACCESS_KEY |
(unset) | Separate ListBucket-only credentials for Admin → Backups freshness monitoring (reusing the writer key refuses startup). |
BACKUP_MAX_AGE_HOURS |
36 |
Hours before the 6-hourly freshness check flags stale backups. |
BACKUP_HEARTBEAT_URL |
(unset) | Optional webhook pinged after a successful backup upload. |
Backup and Restore
Backups are verified custom-format PostgreSQL archives (pg_dump -Fc) and are opt-in (BACKUP_ENABLED=false, BACKUP_SCHEDULE=off by default).
Caution: PostgreSQL dumps are not encrypted bundles and do not include
/dataor your secrets. For full disaster recovery, separately protect:
COCKPIT_CONTEXT_ENCRYPTION_KEYS(required to decrypt saved SSH keys in the DB)BETTER_AUTH_SECRET(required to verify peppered password hashes)- The
/datavolume (specifically any private repositories cloned with a one-time SSH key, which cannot auto-refetch)
Enabling Automated Backups
Add compose.backup.yaml (mounts /backups on app) and the backup Compose profile for daily scheduling, after setting BACKUP_ENABLED=true and BACKUP_SCHEDULE=daily:
docker compose -p cockpit-context \
-f compose.yaml \
-f compose.vps.yaml \
-f compose.backup.yaml \
--profile backup up -d --build
For credential isolation, the container entrypoint runs as PID 1 during startup migrations using BACKUP_S3_ACCESS_KEY_ID / BACKUP_S3_SECRET_ACCESS_KEY, then unsets both variables before execing tini and the Node server. The running web server retains only the separate ListBucket-only BACKUP_MONITOR_S3_* credentials.
Host Backup, Drill & Offline Restore
Run the Linux host helper from your repository checkout, always specifying --project:
# Take an immediate verified database dump
bash scripts/backup/host.sh backup --project cockpit-context
# List available local and S3 dumps
bash scripts/backup/host.sh list --project cockpit-context
# Run a disposable restore drill (verifies archive & migration tables)
bash scripts/backup/host.sh drill --project cockpit-context
# Guided offline restore (prompts before stopping app & backup scheduler)
bash scripts/backup/host.sh restore --project cockpit-context
Restore behavior and exit codes:
- The guided helper prompts
"Stop the app and continue?", stops bothappandbackup, previews the archive and target database, and requires explicit confirmation before replacing data inside a single transaction. - Restored databases automatically receive a 7-day deletion hold (if you restore outside the helper, run the image command
hold-deletions 7before starting the app). - Exit codes:
0= committed cleanly (app remains stopped so you can recover/datasnapshot clones and verifyCOCKPIT_CONTEXT_ENCRYPTION_KEYSbefore runningdocker start);3= refused/cancelled with nothing changed (helper restarts stopped services);4= failed and provably rolled back (helper restarts stopped services);1or129/130/143= uncertain outcome—keep all writers stopped and inspect the database before starting the app.