Skip to content

Docker

This page is for operators who run Adiutor in Docker. It covers the image, a Compose file with PostgreSQL and the background jobs, running it with plain docker run, migrations, the health check, the key for Server Functions, a database on the host and building the image yourself.

Adiutor is published as one image, bastolen/adiutor on Docker Hub. It holds the whole application: the built app, its scripts and migrations, and every dependency. The same image serves the site, runs the background jobs and runs every command, such as migrations and the first-run setup. Why it isn’t two images is in the decision record.

  • Public. Pulling it needs no login.
  • Tags. Every release is published for amd64 and arm64 under its version (for example 0.5.0), its minor line (0.5, which moves to 0.5.1 when that’s out) and latest. Use the exact version, as the examples here do, so an upgrade is a change you make on purpose.
  • No database inside. You provide PostgreSQL 18. The image never migrates on its own: you run the migrations as part of each release (Migrations).
  • Development dependencies stay in. The commands you run on the server need them. Don’t build a slimmer image without them.
  • Unprivileged. It runs as the node user on port 3000 (PORT changes it) with NODE_ENV=production. The application’s own files belong to root. Only the folder where Next.js keeps its caches, and /data/attachments for a volume of attached files, can be written to, so a flaw that lets the server write files can’t change the application’s code.
  • Settings at run time only. Give them with --env-file or env_file, never when building, so they don’t end up in the image.
Terminal window
docker pull bastolen/adiutor:0.5.0

The install script writes the Compose file and the settings file for you. In an empty folder of its own, such as /srv/adiutor, run it, give your address when it asks (https://adiutor.dev in the examples here), and choose PostgreSQL in Docker or your own:

Terminal window
curl -fsSL https://raw.githubusercontent.com/bastolen/adiutor/production/install.sh | sh

With PostgreSQL in Docker, it writes the Compose file below and a .env like the one in The settings file, with a fresh password and secrets and the mail server left to fill in. With your own, it writes the setup A database on the host describes. What the install script does has the details. Then go on with Start it.

To write them yourself instead: this Compose file runs three services, the database, the app and the background jobs. Save it as compose.yaml in a folder of its own, such as /srv/adiutor.

compose.yaml
services:
db:
image: postgres:18-alpine
restart: unless-stopped
environment:
POSTGRES_USER: adiutor
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: adiutor
# No published port: only the other services reach the database, over Compose's own network.
volumes:
- database:/var/lib/postgresql
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U adiutor -d adiutor']
interval: 5s
timeout: 5s
retries: 10
app:
image: bastolen/adiutor:0.5.0
restart: unless-stopped
env_file: .env
environment: &settings
DATABASE_URL: postgresql://adiutor:${POSTGRES_PASSWORD}@db:5432/adiutor
# Keeps attached files in the volume below. Leave both lines out to choose a storage in Settings.
ATTACHMENTS_STORAGE: local
ATTACHMENTS_DIR: /data/attachments
ports:
# Only on the loopback address: for a reverse proxy on the same computer, never the network.
- '127.0.0.1:3000:3000'
volumes:
- attachments:/data/attachments
depends_on:
db:
condition: service_healthy
jobs:
image: bastolen/adiutor:0.5.0
restart: unless-stopped
env_file: .env
environment: *settings
volumes:
- attachments:/data/attachments
# The background jobs' tick: a run, then 5 minutes' pause.
command: ['sh', '-c', 'while true; do pnpm jobs:run; sleep 300; done']
# The image's health check asks the web server, which this container doesn't run.
healthcheck:
disable: true
depends_on:
db:
condition: service_healthy
volumes:
database:
attachments:

What each part does:

  • db is PostgreSQL 18, with its data in the database volume. It publishes no port, so only the other two services reach it, on Compose’s own network. Its health check makes the other services wait until it answers.
  • app is the web server. Its port is published on the loopback address only (127.0.0.1:3000:3000), for a reverse proxy on the same server. Docker’s published ports bypass firewalls such as ufw, so a plain 3000:3000 would put the app on the internet without your proxy. See Reverse proxy.
  • jobs runs the background jobs’ tick every 5 minutes (a run, then a 5 minute pause). A tick that runs late or overlaps another does no harm. It needs the same settings as the app, and the same files volume, because some jobs touch files. Its health check is off because the image’s one asks the web server, which this container doesn’t run. See Background jobs.
  • ATTACHMENTS_STORAGE and ATTACHMENTS_DIR keep attached files in the attachments volume. A staff Admin then presses Set up this folder once, on Settings › Integrations, to mark it as Adiutor’s. Leave both lines out to choose the storage in Settings instead, for example S3 (see File storage).

The install script writes this file. To write it yourself, put a .env next to compose.yaml, with the values written without quotes. For a server at https://adiutor.dev:

POSTGRES_PASSWORD=<openssl rand -hex 24>
BETTER_AUTH_URL=https://adiutor.dev
BETTER_AUTH_SECRET=<openssl rand -base64 32>
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY=<openssl rand -base64 32>
CLIENT_IP_HEADERS=x-real-ip
SMTP_URL=smtps://<user>:<password>@smtp.adiutor.dev:465
EMAIL_FROM=Adiutor <[email protected]>

Replace each placeholder with what the command in it prints. openssl rand -hex 24 gives a password that is safe inside the database address.

  • BETTER_AUTH_SECRET signs cookies and encrypts authenticator secrets: keep it safe, and see Secrets and incidents.
  • NEXT_SERVER_ACTIONS_ENCRYPTION_KEY is explained under The Server Functions key.
  • CLIENT_IP_HEADERS=x-real-ip goes with the reverse proxy set up as Reverse proxy describes.
  • SMTP_URL and EMAIL_FROM set the mail server. Leave both out to set the mail server in Settings instead. See Email.

After changing .env, run docker compose up -d: it recreates the containers whose settings changed. docker compose restart keeps the settings the containers started with.

  1. Pull the image: docker compose pull.
  2. Create the tables: docker compose run --rm app pnpm db:migrate. Compose starts the database first and waits until it answers.
  3. Start everything: docker compose up -d.
  4. Put a reverse proxy with HTTPS in front of the app, as Reverse proxy describes. The app listens on the loopback address only, so the browser reaches it through the proxy.
  5. Open https://adiutor.dev and follow First run right away. Until then, whoever opens /setup first becomes the staff Admin.

To upgrade, see Upgrading.

Without Compose, start the app with the image and your .env:

Terminal window
docker run -d --name adiutor --env-file .env -p 127.0.0.1:3000:3000 \
-e ATTACHMENTS_STORAGE=local -e ATTACHMENTS_DIR=/data/attachments \
-v adiutor-attachments:/data/attachments bastolen/adiutor:0.5.0

Your .env then holds DATABASE_URL too, for a database you provide. The volume keeps attached files: mount the same one on the app and on every container that runs the jobs. Leave the two -e lines and the volume out to choose a storage in Settings.

Run the background jobs’ tick as a one-off container:

Terminal window
docker run --rm --env-file .env -e ATTACHMENTS_STORAGE=local -e ATTACHMENTS_DIR=/data/attachments \
-v adiutor-attachments:/data/attachments bastolen/adiutor:0.5.0 pnpm jobs:run

Call that command from the host’s cron every 5 minutes, writing its output to a log file you rotate: Start the tick has the cron line. Every other command in Commands runs the same way: --rm, your --env-file, the image, then the command.

Migrations bring the database to what the image expects, and the image never runs them by itself. Run them before the new image serves traffic, on first install and again for every release:

Terminal window
docker run --rm --env-file .env bastolen/adiutor:0.5.0 pnpm db:migrate

With Compose, that is docker compose run --rm app pnpm db:migrate. Until you do, the health check answers 503, so a new image running against the old schema shows up as unhealthy. Upgrading has the whole routine.

GET /api/health answers 200 with {"status":"ok"} when the database answers and every migration is applied, and 503 with {"status":"unavailable"} otherwise. A load balancer or monitoring service can use it to hold traffic from a server that can’t reach its database, or that wasn’t migrated.

  • The image’s own health check calls it, so docker ps shows the container as healthy or unhealthy.
  • A database host that doesn’t answer at all makes it answer 503 after 10 seconds, rather than hanging.
  • It works signed out and says nothing more than that. The reason goes to the logs as the migration state or an error code, never connection details. See Logs and errors.
  • It’s never cached.

Next.js encrypts what the browser and the server hand each other for actions with a key that is generated when the app is built. Every copy of a published image therefore has the same one, readable by anyone who pulls it. Adiutor’s actions don’t depend on that key, but give your own so a later change can’t depend on a key everyone knows.

  1. Generate one with openssl rand -base64 32.
  2. Set it as NEXT_SERVER_ACTIONS_ENCRYPTION_KEY in .env.
  3. Keep the same value on every instance and every release. Otherwise a page left open across an upgrade, or served by another instance, can’t use its actions.

Next.js reads it when the server starts, ahead of the built-in one, so the image needs no rebuild.

To use a PostgreSQL 18 that isn’t part of the Compose file, choose your own PostgreSQL in the install script, which writes this setup. To change a file you have, remove the db service and its volume, and move DATABASE_URL from the file to .env (a value in the file’s environment wins over .env). When it runs on the same computer as Docker, the address must be the computer’s, not localhost, which inside a container is the container itself. On Docker Desktop use host.docker.internal; on Linux, use the host’s address on Docker’s network, and let PostgreSQL accept connections there (listen_addresses and pg_hba.conf).

DATABASE_URL='postgresql://adiutor:<password>@host.docker.internal:5432/adiutor'

Keep the single quotes: without them, Compose reads a $ in the password as the start of a variable. Write the password’s other special characters percent-encoded, such as %2F for / and %40 for @.

Remove the depends_on lines too, since they name the service you removed. You look after this database yourself, including its backups: see Upgrading.

You rarely need to, as releases publish the image. To build it from a checkout of a release (for example after changing the build), run this in the checkout’s folder:

Terminal window
docker build -t adiutor .

.dockerignore keeps your node_modules, builds, test output, database files and every .env file out of the image, wherever they are in the folder. The build uses placeholder settings and connects to nothing. Use adiutor as the image name in the commands above.

For https://adiutor.dev on a server with the folder /srv/adiutor:

Terminal window
cd /srv/adiutor
docker compose pull
docker compose run --rm app pnpm db:migrate
docker compose up -d
docker compose ps
curl -s http://127.0.0.1:3000/api/health

Within a minute, docker compose ps shows db and app as healthy, and curl prints {"status":"ok"}. With the reverse proxy in front, open https://adiutor.dev/setup as First run describes, and set up as Alex Admin ([email protected]).

  • Never run pnpm db:seed on a server: it deletes all data.
  • Never use docker compose down -v on a server you keep: -v deletes the database and the files.
  • Back up the database and the files volume together: a file is found by its row in the database.
  • Never set EMAIL_OUTBOX_DIR: it’s for the tests.

Adiutor's code is released under the MIT License. The Adiutor name and logo aren’t covered by it; see the notice.

Set in Inter and JetBrains Mono, under the SIL Open Font License (Inter, JetBrains Mono).