# Deploy and operate

> What the Docker Compose stack contains, how updates work, how to back up and restore, where the logs are, and how to deploy these docs as their own service.

Source: https://crawl-docs.pdhq.win/advanced/deploy-and-operate/
Last updated: 2026-12-04

## The stack

`docker-compose.yml` at the repository root defines three services:

| Service | Image | Port | Alias | Notes |
| --- | --- | --- | --- | --- |
| `db` | `postgres:17-alpine` | 5432 (not published) | `sc-db` | Volume `pgdata`. A health check (`pg_isready`) gates the API's start. |
| `api` | built from `deploy/api.Dockerfile` | 4000 | `sc-api` | Runs as the `node` user. Volume `bundles` at `/data/bundles`. Has ffmpeg. Health check on its port. |
| `web` | built from `deploy/web.Dockerfile` | 3000 | none | Next.js standalone server. Reaches the API at `http://sc-api:4000`. |

Every service joins a private `backend` network and, for `api` and `web`, Dokploy's shared `dokploy-network` (an **external** network that Dokploy creates). Services reach each other by the aliases `sc-db` and `sc-api`, which cannot clash with another application's `db` or `api` on the shared network. No ports are published: Dokploy's proxy reaches the containers by name and gives each domain HTTPS.

The API image has two targets. `runtime` is the normal Alpine image. `runtime-speech` is Debian with Whisper (about 3 GB), chosen with `API_TARGET=runtime-speech`. The extension is built into the API image so that Settings can offer it.

## Updates

With **Auto Deploy** on, Dokploy rebuilds and restarts the stack whenever the branch changes. It does so whether or not CI passed, so protect the branch (require the `check` job) and merge only through pull requests.

Tables are altered at start by `synchronize` (see [Data model](https://crawl-docs.pdhq.win/advanced/data-model.md)). Back up first.

To roll back, deploy an earlier commit. Because tables are changed in place, a rollback after a table change may need a restore from backup.

## Back up and restore

| What | Where | How |
| --- | --- | --- |
| Posts, tags, notes, shares, settings | PostgreSQL | `pg_dump` of the database, or a volume snapshot of `pgdata`. Or copy to another database from Settings, see [Copy the database](https://crawl-docs.pdhq.win/guide/database-copy.md). |
| Saved files | The `bundles` volume, or R2, or WebDAV | A volume snapshot, a copy of the bucket, or the WebDAV's own backup. |

A restored database without its files shows posts that have no pictures or videos, and the other way round. Back up both at the same time.

## Logs

Read the API's log in Dokploy's **Logs** tab. It names the cause of start failures (a wrong environment value is reported by name), WebDAV fallbacks ("that file goes to the main storage instead") and speech settings that name a missing program. The web app's log shows proxy and rendering errors.

## Checks that run in CI

`.github/workflows/ci.yml` runs on every pull request and on pushes to `main`:

- the dependency audit (`yarn npm audit --all --recursive`), which fails on any advisory;
- `deploy/check-compose.sh`, which resolves the compose file the way Dokploy does in each situation (with and without `POSTGRES_PASSWORD` or `DATABASE_URL`) and needs no Docker daemon;
- lint, type checks and unit tests for the packages and apps, with a real PostgreSQL for the database-copy tests;
- the extension's build and browser tests, and the build of the API and web app;
- a boot check that starts the built API against the job's database and asks `/health`.

## Deploy these docs

The docs are static files with their own container: a Dockerfile that builds them and serves them with nginx. They are their own Dokploy service, separate from the app, so they keep working while the app is down and a docs problem cannot stop an app deploy. Two kinds of Dokploy service work, and both build the same image from `deploy/docs.Dockerfile`.

### As a Compose service

Use this if you already have the app as a Compose service and want the docs to look the same.

1. In the same Dokploy project create a **Compose** service from the same repository and branch `main`. Set **Compose Path** to `./deploy/docs.compose.yml` (the default `./docker-compose.yml` is the app).
2. In **Environment** set `DOCS_SITE_URL` to the docs' public address, for example `https://docs.example.com`. It is required: the deploy stops and names it when it is missing, because the canonical links and the sitemap would otherwise point at a placeholder. If you want the **Open the app** button, also set `NEXT_PUBLIC_DOCS_APP_URL` to the app's address.
3. In **Domains** add a domain such as `docs.example.com` with **Service Name** `docs`, **Port** `80` and HTTPS.
4. Press **Deploy**.

### As an Application

1. In Dokploy create an **Application** from the same repository.
2. Build type **Dockerfile**, Dockerfile path `deploy/docs.Dockerfile`, build context `.`.
3. Under **Build Time Arguments** set `DOCS_SITE_URL` to the docs' public address (for example `https://docs.example.com`) and, if you want the **Open the app** button, `NEXT_PUBLIC_DOCS_APP_URL`.
4. Add a domain such as `docs.example.com` on port **80** with HTTPS.

Either way, both values are build arguments: they are written into the pages when the image is built, so changing one needs a new **Deploy**. The Compose file is also checked by `deploy/check-compose.sh` in CI.

> [!NOT-TESTED]
> The docs image was not built here, because the build environment has no Docker engine. The site itself was built with `next build` and served and inspected in a real browser. The nginx file was not run.

## Without Docker

To run the pieces by hand, see [Build, test and extend](https://crawl-docs.pdhq.win/advanced/build-test-extend.md).
