---
title: "Production Compose"
description: "Run TRUSTIVAN on one host with the production Compose file: the nine services, three database roles, the environment file and how each service is confined."
---

<Note>
**Self-hosting is by agreement.** The container images (`ghcr.io/trustivan/*`)
and the source repository are private: they are provided to customers who run
TRUSTIVAN on their own infrastructure. To evaluate TRUSTIVAN, use the hosted
service from the [quickstart](/getting-started/quickstart), or [contact
us](https://trustivan.com/contact/) about self-hosting.
</Note>

The repository ships two Compose files, and they are not interchangeable.

| File | Purpose |
|---|---|
| `docker-compose.yml` at the repository root | The development stack. Builds from source, `ENV=development`, default database credentials. See [Docker Compose](/installation/docker-compose) |
| `infra/docker/docker-compose.prod.yml` | The deployment stack. Published images, `ENV=production`, no default secrets, a separate migration step and separate database roles |

This page is about the second. It runs the real images with the real
strictness on **one host**. That is a legitimate deployment for a single
organization or a pilot, and an honest staging environment. It is not highly
available: one host failing takes everything with it.

## What it runs

| Service | Runs | Role |
|---|---|---|
| `postgres` | `postgres:16-alpine`, pinned by digest | The system of record |
| `redis` | `redis:7-alpine`, pinned by digest, append-only | The scan wakeup queue |
| `migrate` | Backend image, `/app/migrate up` | One-shot. Applies migrations as the schema owner, then exits |
| `db-roles` | `postgres:16-alpine` running `db-roles.sh` | One-shot. Creates the two application login roles after the migrations |
| `api` | Backend image | The API, with `SCAN_WORKER_ENABLED=false` |
| `worker` | Backend image, `/app/worker` | The scan worker |
| `dashboard` | Dashboard image | The web console |
| `reencrypt` | Backend image, `/app/reencrypt` | On demand only, in the `maintenance` profile. See [`reencrypt`](/cli-reference/reencrypt) |
| `prometheus`, `alertmanager`, `grafana`, `node-exporter` | Pinned by digest | Only with `--profile monitoring`. See [Observability](/deployment/observability#running-prometheus-alertmanager-and-grafana) |

The start order is enforced by the file. `postgres` must be healthy before
`migrate` runs. `migrate` must exit successfully before `db-roles` runs.
`db-roles` must exit successfully before `api` and `worker` start. A failed
migration therefore stops the deploy instead of leaving an application running
against a schema it does not expect.

Every service is confined the same way: a read-only root filesystem, every
Linux capability dropped, `no-new-privileges`, and a non-root user (`postgres`
runs as its image's `postgres` user, uid 70, and `redis` as `redis`). Each
writable path is a named volume or a small `tmpfs` the process was observed to
need. The worker, which unpacks untrusted images, is also bounded to a 2&nbsp;GB
`/tmp`, 4&nbsp;GB of memory, 2 CPUs and 512 processes. Every third-party image
is pinned by digest, so a moved tag cannot change what runs.
`scripts/ci/check-deployment.sh` fails the build on a service that lacks any of
this.

On a stop, the API stops accepting connections and waits at most 20 seconds
for open ones before it closes the database pools and exits. The `api` service
allows 30 seconds (`stop_grace_period`) so that wait fits before Docker kills
the process, and the `worker` allows 45.

## Before you start

- **A TLS-terminating reverse proxy.** Nothing in the stack terminates TLS.
  The three published ports bind to loopback by default so that the proxy is
  the only way in.
- **Access to the images.** The example file notes that the published packages
  are private, so the host needs `docker login ghcr.io` with a token that can
  read them before Compose can pull.
- **A dashboard image built for this stack.** The dashboard proxies `/api/*`
  to the backend, and that destination is fixed when the image is built. An
  image built with the default proxies to its own loopback and every API call
  fails. Build it with the API's service name:

  ```bash
  docker build --build-arg API_PROXY_URL=http://api:8080 \
    -f dashboard/Dockerfile -t registry.example.com/trustivan-dashboard:1.0.0 .
  ```

- **A decision about vulnerability data.** `VULN_DB_PROVIDER` has no default
  here. See [Vulnerability database](/configuration/vulnerability-database).

## Install

<Steps>
  <Step title="Create the environment file">
    ```bash
    cp infra/docker/.env.prod.example infra/docker/.env
    ```

    Never commit it. Compose reads it only to fill in the `${...}` references
    in the compose file. For anything larger than one host, prefer a secret
    manager that injects the same variables.
  </Step>

  <Step title="Pin the images">
    ```bash
    BACKEND_IMAGE=ghcr.io/trustivan/trustivan-backend@sha256:<digest>
    DASHBOARD_IMAGE=registry.example.com/trustivan-dashboard@sha256:<digest>
    ```

    Pin by digest. A tag is a pointer that can be moved, and a container
    recreated months later would then run something nobody deployed. The
    digests in the example file are placeholders and do not pull. Get a real
    one with:

    ```bash
    docker buildx imagetools inspect ghcr.io/trustivan/trustivan-backend:v1.0.0 \
      --format '{{.Manifest.Digest}}'
    ```
  </Step>

  <Step title="Set the three database identities">
    Generate each password with `openssl rand -hex 32`. Hex needs no escaping
    inside a URL. Use a different one for each.

    ```bash
    POSTGRES_DB=trustowl
    POSTGRES_USER=trustowl_owner
    POSTGRES_PASSWORD=<owner password>

    MIGRATION_DATABASE_URL=postgresql://trustowl_owner:<owner password>@postgres:5432/trustowl?sslmode=disable
    DATABASE_URL=postgresql://trustowl_app_login:<app password>@postgres:5432/trustowl?sslmode=disable
    JOB_DATABASE_URL=postgresql://trustowl_job_login:<job password>@postgres:5432/trustowl?sslmode=disable
    ```

    You do not create the last two roles. See
    [the three roles](#the-three-database-roles) below.
  </Step>

  <Step title="Set the secrets">
    ```bash
    JWT_SECRET=<openssl rand -hex 32>
    TOKEN_ENCRYPTION_KEY=<openssl rand -hex 32>
    ```

    Store `TOKEN_ENCRYPTION_KEY` in a secret manager, separately from the
    database. A database backup without it restores rows nobody can decrypt.
  </Step>

  <Step title="Set the origins">
    ```bash
    DASHBOARD_URL=https://app.example.com
    WEBSITE_URL=https://www.example.com
    API_BASE_URL=https://api.example.com
    ```

    `DASHBOARD_URL` is also the whole CORS allow-list. `API_BASE_URL` is
    optional: it is the callback origin registered with customers' identity
    providers, and single sign-on is unavailable without it. When set it must
    be `https://` and must not be a loopback address.
  </Step>

  <Step title="Choose the vulnerability data source">
    ```bash
    VULN_DB_PROVIDER=mirror
    VULN_DB_REPOSITORIES=<your registry references>
    ```

    `mirror` with no repositories is a startup failure. `upstream` also
    requires `VULN_DB_ACKNOWLEDGE_UPSTREAM=true`.
  </Step>

  <Step title="Decide who may sign up">
    ```bash
    SIGNUP_MODE=invite_only
    ```

    The example file sets `invite_only`. If the variable is missing from your
    file, the compose file passes `open`. See
    [Sign-up and sign-in](/configuration/sign-up-and-sign-in).
  </Step>

  <Step title="Start the stack">
    ```bash
    docker compose -f infra/docker/docker-compose.prod.yml --env-file infra/docker/.env up -d
    ```

    Every required value uses Compose's `${VAR:?message}` form, so an unset
    one fails the whole command with a message naming it, before anything
    starts.
  </Step>

  <Step title="Check it">
    ```bash
    docker compose -f infra/docker/docker-compose.prod.yml --env-file infra/docker/.env ps
    curl -s http://127.0.0.1:8080/ready
    ```

    `migrate` and `db-roles` should show as exited with status 0. `api`,
    `worker` and `dashboard` should be healthy.
  </Step>
</Steps>

## The three database roles

| Role | Connection variable | Used by | Bound by row-level security |
|---|---|---|---|
| The owner, `POSTGRES_USER` | `MIGRATION_DATABASE_URL` | `migrate`, `db-roles`, `reencrypt` | No. In this stack it is the cluster superuser |
| `trustowl_app_login` | `DATABASE_URL` | `api`, and the worker's per-organization work | Yes, to one organization per transaction |
| `trustowl_job_login` | `JOB_DATABASE_URL` | `worker` | Yes, by a narrow cross-organization policy for queue and maintenance work |

`db-roles` creates the two login roles on every deploy, sets their passwords
from the URLs you wrote, and grants them the group roles the migrations
created. It refuses to continue when a URL has no password, when either
application URL names the owner, or when both application URLs name the same
role.

The backend enforces the same separation from its side. Outside development
the API refuses to start as a superuser or a `BYPASSRLS` role, and the worker
refuses to start without a job-plane role, because on the application role it
would never see a queued scan.

## Published ports

| Variable | Default | Service |
|---|---|---|
| `API_BIND` | `127.0.0.1:8080` | `api` |
| `DASHBOARD_BIND` | `127.0.0.1:3000` | `dashboard` |

`postgres` and `redis` publish nothing. Point your reverse proxy at the three
loopback addresses.

The API sees your reverse proxy, and the dashboard's own `/api` proxy, as its
network peer. The compose file therefore sets `TRUSTED_PROXIES` to the private
ranges `10.0.0.0/8,172.16.0.0/12,192.168.0.0/16` by default, so the API
believes their `X-Forwarded-For`. Without that, every client would share one
address and the per-address sign-in limiter would lock everyone out together.
Narrow it only if you move `API_BIND` off loopback.

## What the file fixes for you

These are set in the compose file, not in your environment file:

| Setting | Value | Why |
|---|---|---|
| `ENV` | `production` | Strict validation, and no generated secrets |
| `RUN_MIGRATIONS_ON_START` | `false` | The application roles cannot change the schema. `migrate` does it |
| `REDIS_URL` | `redis://redis:6379` | The stack's own Redis |
| `METRICS_ADDR` | `0.0.0.0:9090` | Reachable on the Compose network. The port is not published to the host |
| `SCAN_WORKER_ENABLED` | `false` on `api`, `true` on `worker` | The split described in [Topology](/deployment/topology) |
| `SCANNER_CACHE_DIR` | `/cache` on `worker` | Backed by the `scanner_cache` volume |
| `JWT_SECRET` | Given to `api` and `reencrypt` only | The worker verifies no session and should not hold the key that signs one |

## Which variables reach the containers

Compose gives a container only the variables its service names. The
`--env-file` you pass fills in `${...}` references in the compose file; it is
not handed to the containers. So the file names every setting the backend
reads, each passed through **empty when you have not set it**, and the backend
treats an empty value exactly as an unset one. A setting in
[Environment variables](/configuration/environment) therefore takes effect when
you write it into your environment file, with no edit to the compose file.

Settings that only the API uses are given to `api` alone: `JWT_SECRET` and
`JWT_SECRET_PREVIOUS`, the session lifetimes, `TRUSTED_PROXIES`,
`STAFF_ALLOWED_CIDRS`, the GitHub, GitLab and Google sign-in variables, the
GitHub App, and `BILLING_PROVIDER` with the `STRIPE_` variables. The worker,
which unpacks untrusted images, holds none of them. Everything else (database
pool bounds, key rotation, scanning, feeds, tracing) goes to `api`, `worker`
and `reencrypt` alike.

**One exception at this release:** `SECRETS_REQUIRE_BOUND` is read by the
backend and not named in the compose file, so it does not reach a container
from the environment file. Add it with a second Compose file rather than by
editing the shipped one, so an upgrade does not overwrite your change:

```yaml
# infra/docker/local.override.yml
services:
  api:
    environment:
      SECRETS_REQUIRE_BOUND: ${SECRETS_REQUIRE_BOUND:-false}
  worker:
    environment:
      SECRETS_REQUIRE_BOUND: ${SECRETS_REQUIRE_BOUND:-false}
  reencrypt:
    environment:
      SECRETS_REQUIRE_BOUND: ${SECRETS_REQUIRE_BOUND:-false}
```

Then name both files on every command, in this order:

```bash
docker compose \
  -f infra/docker/docker-compose.prod.yml \
  -f infra/docker/local.override.yml \
  --env-file infra/docker/.env up -d
```

Read [Row binding](/deployment/key-rotation#row-binding) before you switch it
on.

To confirm a variable reached a process, read it from the container rather
than from your file:

```bash
docker compose -f infra/docker/docker-compose.prod.yml \
  --env-file infra/docker/.env exec api printenv SIGNUP_MODE
```

<Warning>
**Upgrading from a release before 2026-10-13?** Until then the file passed
about thirty variables and silently dropped the rest, including
`TOKEN_ENCRYPTION_KEY_VERSION`, `TOKEN_ENCRYPTION_KEYS_PREVIOUS`, the `DB_`
pool bounds, `OTEL_EXPORTER_OTLP_ENDPOINT`, and the sign-in provider and Stripe
settings. Any of those written into your environment file and never seen by the
process **take effect on the first deploy of this release**. Read your
environment file before you deploy and remove anything you do not mean. If you
added them through an override file, that still works; the override's value
wins.

The same deploy recreates `postgres` and `redis` once, because their user and
filesystem settings changed. Their volumes keep their data. See the
[upgrade notes](/changelog/upgrade-notes).
</Warning>

## Upgrading

Change the image references in the environment file and run the same `up -d`
command. `migrate` and `db-roles` run again, in order, before the new `api`
and `worker` start. See [Upgrades](/deployment/upgrades) for what to check
first and how to roll back.

## Related

- [Deployment topology](/deployment/topology): what to run and where, beyond
  one host.
- [Environment variables](/configuration/environment): every setting.
- [Backup and recovery](/deployment/backup-and-recovery): the backup scripts
  that read this same environment file.
