---
title: "Docker Compose"
description: "The development Compose stack at the repository root: its core services, why the API and the worker are separate processes, and what to change before deploying."
---

<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>

Docker Compose is the supported installation path today, and the repository
ships two Compose files. This page covers the one at the repository root, which
is the **development** stack: it builds from source, runs with
`ENV=development`, and brings up PostgreSQL, Redis, the API and a scan worker.
To deploy, use the other one. See
[Production Compose](/installation/production-compose).

```bash
docker compose up -d
```

## The four core services

| Service | Image | Role |
|---|---|---|
| `postgres` | `postgres:16-alpine` | The system of record. Database `trustowl` |
| `redis` | `redis:7-alpine` | The scan wakeup queue |
| `backend` | built from `./backend` | The API, on port 8080 |
| `worker` | built from `./backend` | The scan worker, `command: /app/worker` |

Both `postgres` and `redis` declare healthchecks, and the two application
services `depend_on` them with `condition: service_healthy`. That is what stops
the API racing its own database on a cold start: it does not begin until
`pg_isready` and `redis-cli ping` both succeed.

The API and the worker are built from the same image. Two images would have
identical dependencies and identical build steps, and would drift the first time
only one of them was rebuilt, so the binary is selected by the command instead.

The same file also starts the NHI Security services (`nhi-postgres`,
`nhi-migrate`, `nhi-api` and `nhi-web`), with its own database. They are on by
default and built from `nhi/`.

## Why the split is the default

`backend` runs with `SCAN_WORKER_ENABLED=false`; `worker` runs the same image as
`/app/worker`.

The API can run the worker in-process (that is the default when you set
nothing), and a single binary with a PostgreSQL and a Redis is a complete
TRUSTIVAN. The compose file nevertheless splits them, deliberately:

> If the two can only run together, "a scan survives a worker restart" is a
> story rather than a property, and nobody discovers otherwise until production.

Splitting them in the default configuration means the durability path is
exercised every time anyone runs the stack, rather than the first time someone
needs it. It also matches the workload's actual shape: requests are
milliseconds, scans are minutes, so the two want to scale independently.

## The worker needs no Docker socket

Note what is absent from the `worker` service: there is no
`/var/run/docker.sock` mount and no privileged flag.

The scanner resolves images from remote registries only. Mounting a runtime
socket into the process that handles untrusted input would be root on the host,
and consulting a local image store would let a caller-supplied reference resolve
to another tenant's image. Neither is a trade TRUSTIVAN makes.

## Volumes

```yaml
volumes:
  postgres_data:
  redis_data:
  scanner_cache:
```

`scanner_cache` is mounted at `/cache` in the worker and is the one worth
understanding. It holds the vulnerability database and the image blob cache.
Persisting it is the difference between a scan taking seconds and taking
minutes, because without it every worker restart re-downloads roughly 50&nbsp;MB
before it can match anything.

It is also safely disposable: discarding it costs one slow scan, not any data.
See [Upgrades](/deployment/upgrades).

## Secrets are not in the compose file

The compose file carries no `JWT_SECRET` and no `TOKEN_ENCRYPTION_KEY`, and this
is not an omission.

`JWT_SECRET` was once hardcoded here as a published literal that was also the
config layer's default, so anyone who read the repository could forge a token
for any user. That was a real security finding. In development the backend now
generates an ephemeral random key per process and logs that it did so; in any
deployed environment it refuses to start without one.

For anything beyond local development, supply real values through a `.env` file
or your orchestrator's secret mechanism:

```bash
cp .env.example .env
openssl rand -hex 32   # JWT_SECRET
openssl rand -hex 32   # TOKEN_ENCRYPTION_KEY
```

[Environment variables](/configuration/environment) has the full list and
what happens when each is missing.

## Adapting it for a deployment

The shipped file targets local development: `ENV=development`, PostgreSQL with
`postgres`/`postgres` credentials, `sslmode=disable`, and both database ports
published to the host. Before deploying it anywhere real, change at minimum:

```yaml
environment:
  ENV: production
  DATABASE_URL: postgresql://trustowl_app_login:<password>@postgres:5432/trustowl?sslmode=require
  # the worker only
  JOB_DATABASE_URL: postgresql://trustowl_job_login:<password>@postgres:5432/trustowl?sslmode=require
  JWT_SECRET: ${JWT_SECRET}
  TOKEN_ENCRYPTION_KEY: ${TOKEN_ENCRYPTION_KEY}
  DASHBOARD_URL: https://app.example.com
  WEBSITE_URL: https://www.example.com
```

`ENV` is a security control rather than a label. Anything that is not
`development`, an unset `ENV` included, is treated as deployed and validated
strictly, so a typo such as `prodction` fails closed rather than open.

Outside development the backend refuses to start as a superuser or a
`BYPASSRLS` role (which the `postgres` user is), and a worker refuses to start
without a job-plane role, because on the application role it would never see a
queued scan. `infra/docker/docker-compose.prod.yml` is the production-shaped
file that does all of this for you, including creating both login roles. See
[Production Compose](/installation/production-compose).

Remove the `ports:` mappings on `postgres` and `redis` unless you genuinely need
to reach them from the host; inside the compose network the services address
each other by name regardless.

## Checking it came up

```bash
docker compose ps
curl -s localhost:8080/ready
```

`/ready` checks the database and Redis and returns 503 while either is
unavailable. `/health` is a liveness probe and deliberately checks nothing. See
[Health and metrics](/deployment/observability) for why conflating the two
is harmful.

Database migrations run automatically as the API starts, so there is no separate
setup step. [Database migrations](/installation/database-migrations)
explains what that involves and how to run them by hand.

## The `make` wrappers

`make docker-up`, `docker-down`, `docker-logs` and `docker-rebuild` run
`docker compose` against this development file from the repository root. They
never start the production file in `infra/docker/`, which demands real secrets
and pinned images and is started with its own command.

## Next

- [Production Compose](/installation/production-compose): the deployment
  stack.
- [Configuration overview](/configuration/overview): the settings model.
- [Deployment topology](/deployment/topology): what to run, and where.
- [Quickstart](/getting-started/quickstart): a first scan; set
  `TRUSTIVAN_URL` to this stack's address.
