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.
The image
Section titled “The image”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 to0.5.1when that’s out) andlatest. 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
nodeuser on port 3000 (PORTchanges it) withNODE_ENV=production. The application’s own files belong to root. Only the folder where Next.js keeps its caches, and/data/attachmentsfor 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-fileorenv_file, never when building, so they don’t end up in the image.
docker pull bastolen/adiutor:0.5.0Run it with Docker Compose
Section titled “Run it with Docker Compose”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:
curl -fsSL https://raw.githubusercontent.com/bastolen/adiutor/production/install.sh | shWith 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.
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:
dbis PostgreSQL 18, with its data in thedatabasevolume. 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.appis 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 plain3000:3000would put the app on the internet without your proxy. See Reverse proxy.jobsruns 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_STORAGEandATTACHMENTS_DIRkeep attached files in theattachmentsvolume. 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 settings file
Section titled “The settings file”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.devBETTER_AUTH_SECRET=<openssl rand -base64 32>NEXT_SERVER_ACTIONS_ENCRYPTION_KEY=<openssl rand -base64 32>CLIENT_IP_HEADERS=x-real-ipSMTP_URL=smtps://<user>:<password>@smtp.adiutor.dev:465EMAIL_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_SECRETsigns cookies and encrypts authenticator secrets: keep it safe, and see Secrets and incidents.NEXT_SERVER_ACTIONS_ENCRYPTION_KEYis explained under The Server Functions key.CLIENT_IP_HEADERS=x-real-ipgoes with the reverse proxy set up as Reverse proxy describes.SMTP_URLandEMAIL_FROMset 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.
Start it
Section titled “Start it”- Pull the image:
docker compose pull. - Create the tables:
docker compose run --rm app pnpm db:migrate. Compose starts the database first and waits until it answers. - Start everything:
docker compose up -d. - 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.
- Open
https://adiutor.devand follow First run right away. Until then, whoever opens/setupfirst becomes the staff Admin.
To upgrade, see Upgrading.
Run it with docker run
Section titled “Run it with docker run”Without Compose, start the app with the image and your .env:
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.0Your .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:
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:runCall 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
Section titled “Migrations”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:
docker run --rm --env-file .env bastolen/adiutor:0.5.0 pnpm db:migrateWith 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.
The health check
Section titled “The health check”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 psshows 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.
The Server Functions key
Section titled “The Server Functions key”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.
- Generate one with
openssl rand -base64 32. - Set it as
NEXT_SERVER_ACTIONS_ENCRYPTION_KEYin.env. - 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.
A database on the host
Section titled “A database on the host”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.
Building the image yourself
Section titled “Building the image yourself”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:
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.
Example
Section titled “Example”For https://adiutor.dev on a server with the folder /srv/adiutor:
cd /srv/adiutordocker compose pulldocker compose run --rm app pnpm db:migratedocker compose up -ddocker compose pscurl -s http://127.0.0.1:3000/api/healthWithin 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]).
Good to know
Section titled “Good to know”- Never run
pnpm db:seedon a server: it deletes all data. - Never use
docker compose down -von a server you keep:-vdeletes 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.
Related
Section titled “Related”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).