Trilium Notes with Docker Compose
Build your personal knowledge base with Trilium Notes In the project's words: Trilium Notes on GitHub (repository description) checked 2026-10-01
Runs on: amd64, arm64, arm/v7, arm/v8 from each image's registry manifest, checked 2026-10-01; a CPU counts only if every image has a build for it. Image by image
Add Trilium Notes to the builder to use your own domain and combine it with other apps in one file.
What Trilium Notes needs
Only figures Trilium Notes's own documentation publishes, each linked to the page it is on. Where the project gives no number, this page does not invent one.
| Resource | Minimum | Recommended |
|---|---|---|
| RAM | The project publishes no figure | |
| CPU | The project publishes no figure | |
| Disk | The project publishes no figure | |
Which hardware Trilium Notes has images for
Read from each image's manifest list in its registry (anonymous, read-only) when this page was built. An app counts for a CPU only if every one of its images lists it.
- x86-64 PC or NAS (
linux/amd64): every image has a build. - Raspberry Pi 4/5, 64-bit OS (
linux/arm64): every image has a build. - Raspberry Pi 3 or Zero 2 W, 32-bit OS (
linux/arm/v7): every image has a build.
| Service | Image | Platforms in the manifest | Digest | Registry | Checked |
|---|---|---|---|---|---|
trilium | triliumnext/trilium:latest | arm64, arm/v8, arm/v7, amd64 | sha256:be93e82699b12950ac4e2e7b565ce092fe215b8dd6ddfc47921e37b49e6a0e8b | registry-1.docker.io | 2026-10-01 |
docker-compose.yml
This is exactly what the builder writes for Trilium Notes alone on example.org: the official definition with its published ports removed and Caddy added in front.
# docker-compose.yml built at dankhost.com for: Trilium Notes # Each app block is its official compose definition. Only the names were prefixed with # the app slug (services, containers, volumes, bind folders, .env variables) so any set of # apps can share one file; other differences are listed under "Changed:" in each block. # Only Caddy publishes ports. Secrets live in .env next to this file. services: # ---- Caddy: the one reverse proxy, HTTPS certificates from Let's Encrypt ---- # Source: https://caddyserver.com/docs/running (checked 2026-09-23) # Source: https://github.com/dani-garcia/vaultwarden/wiki/Using-Docker-Compose (checked 2026-09-23) # Caddyfile goes in ./caddy/Caddyfile. Fixed address 172.30.0.2 so apps can trust it exactly. caddy: image: "caddy:2" container_name: "caddy" restart: "unless-stopped" ports: - "80:80" - "443:443" - "443:443/udp" volumes: - "./caddy:/etc/caddy" - "caddy-data:/data" - "caddy-config:/config" networks: proxy: ipv4_address: "172.30.0.2" # ---- Trilium Notes (trilium.example.org) ---- # Source: https://github.com/TriliumNext/Trilium/blob/main/docker-compose.yml (checked 2026-10-01) # Source: https://github.com/TriliumNext/Trilium/blob/main/docs/User%20Guide/User%20Guide/Installation%20%26%20Setup/Server%20Installation/1.%20Installing%20the%20server/Using%20Docker.md (checked 2026-10-01) # Source: https://github.com/TriliumNext/Trilium/blob/main/docs/User%20Guide/User%20Guide/Installation%20%26%20Setup/Server%20Installation/2.%20Reverse%20proxy/Trusted%20proxy.md (checked 2026-10-01) # Source: https://github.com/TriliumNext/Trilium/blob/main/docs/User%20Guide/User%20Guide/Advanced%20Usage/Configuration%20(config.ini%20or%20environment%20variables).md (checked 2026-10-01) # Changed: Removed the documented '8080:8080' port; Caddy reaches trilium:8080 on the proxy network. # Added TRILIUM_NETWORK_TRUSTEDREVERSEPROXY: "true", the environment form of the Trusted proxy page's trustedReverseProxy=true, so Trilium takes the visitor's address from X-Forwarded-For (for logins and rate limiting) instead of seeing every request come from the proxy. trilium: image: "triliumnext/trilium:latest" container_name: "trilium" restart: "unless-stopped" environment: TRILIUM_NETWORK_TRUSTEDREVERSEPROXY: "true" volumes: - "./trilium/trilium-data:/home/node/trilium-data" - "/etc/timezone:/etc/timezone:ro" - "/etc/localtime:/etc/localtime:ro" networks: proxy: {} networks: # Pinned so the trusted-proxy address given to each app (172.30.0.2) is exact. # If "docker compose up" reports "Pool overlaps", change 172.30.0 here, in Caddy's # ipv4_address and in every trusted-proxy value to a free 172.x.0 range. proxy: ipam: config: - subnet: "172.30.0.0/24" ip_range: "172.30.0.128/25" gateway: "172.30.0.1" volumes: caddy-data: caddy-config:
Caddyfile save as caddy/Caddyfile
Caddy gets and renews the HTTPS certificate for trilium.example.org by itself once the DNS record points at your server and ports 80 and 443 reach it.
# Caddyfile built at dankhost.com. Save it as ./caddy/Caddyfile next to docker-compose.yml.
# Caddy gets and renews a Let's Encrypt certificate for each name below by itself,
# once the DNS records point at this server and ports 80 and 443 reach it.
# Trilium Notes
trilium.example.org {
reverse_proxy trilium:8080
}
.env
Trilium Notes needs no secret here; the builder adds nothing you have to fill in by hand.
# .env for Trilium Notes, from dankhost.com/app/trilium/. Nothing here is secret. # Keep this file private (chmod 600). # None of the chosen apps needs a variable here.
Changes from the official file
Besides prefixing every service, container, volume, folder and variable with trilium (so any set of apps can share one file), these are all the differences from what the project documents:
- Removed the documented '8080:8080' port; Caddy reaches trilium:8080 on the proxy network.
- Added TRILIUM_NETWORK_TRUSTEDREVERSEPROXY: "true", the environment form of the Trusted proxy page's trustedReverseProxy=true, so Trilium takes the visitor's address from X-Forwarded-For (for logins and rate limiting) instead of seeing every request come from the proxy.
Notes for Trilium Notes behind the proxy
- Open https://trilium.example.org: on the first visit Trilium asks whether to start a new document or sync from another server, and you set the password there. Until you do, whoever opens the address first chooses it.
- Before the first start: mkdir -p ./trilium/trilium-data. The container starts as root, gives the folder to UID 1000 and runs Trilium as that user (the Docker page).
- The file uses the tag 'latest'; its own comment suggests a version tag such as v0.90.3 instead, because latest "may cause unintended updates".
- /etc/timezone and /etc/localtime are mounted read-only from the host, as in the file. On a host without /etc/timezone, delete that line.
How to run it
- At your DNS provider, add an A record named
triliumon your domain pointing at the server's public IP address, and forward TCP 80, TCP 443 and UDP 443 to it. - Save the three files in one folder:
docker-compose.ymland.envside by side, the Caddyfile at./caddy/Caddyfile. Replaceexample.orgwith your domain in the Caddyfile, the compose file and the .env, or let the builder do it. - Nothing in
.envneeds filling in;chmod 600 .envall the same. - Start it:
docker compose up -d docker compose logs -f caddy # watch the certificate arrive
- Open the new address (
trilium.plus your domain) in a browser and follow the notes above.
Back it up
Trilium copies its own database once a day, once a week, once a month and before each migration into backup/ in the data directory, and the docs encourage "some better backup solution", such as copying the database to another computer. Here that is the whole ./trilium-data folder.
Below is the BACKUP.md the builder writes next to the compose file above: which of its folders and volumes hold data, what to copy with which container stopped, and a restore check. Pick more apps in the builder and it covers them all in one file.
# BACKUP.md built at dankhost.com for: Trilium Notes
What to copy from the docker-compose.yml built with this file, the database dump each project documents (rewritten for the service names in that file), what to copy with which container stopped, and how to check the result. Run every command in the folder that holds docker-compose.yml.
The folders are owned by the containers' users: put sudo in front of tar if it says "Permission denied". Named volumes live under /var/lib/docker/volumes, not next to the compose file, so they are copied through a throwaway ubuntu container (Docker's documented --volumes-from method). tar makes a full copy each run; for large folders an incremental tool (restic, borg, rsync) saves time and space.
Never run "docker compose down -v" on this file: it deletes the named volumes of every app in it.
## Before you start
BACKUP=/mnt/backup/selfhost # change this: a disk or machine other than this server's system disk
mkdir -p "$BACKUP"
## Every time: the three stack files
tar czf "$BACKUP/stack-files.tar.gz" docker-compose.yml .env caddy
.env holds the database passwords and secret keys the apps were set up with; keep this archive as private as the data.
## Caddy (the reverse proxy)
Caddy's docs: 'The data directory must not be treated as a cache.' It holds the TLS certificates and their private keys; without it Caddy has to ask Let's Encrypt for every certificate again.
- caddy-data (named volume, /data in caddy)
BACK UP: TLS certificates, private keys, OCSP staples.
- caddy-config (named volume, /config in caddy)
SKIP: the last active configuration, kept for 'caddy run --resume', which this setup does not use: it starts from the Caddyfile.
- ./caddy (/etc/caddy in caddy)
IN stack-files.tar.gz: the Caddyfile, copied with the stack files above.
Copy (Caddy keeps serving while you copy):
docker run --rm --volumes-from caddy -v "$BACKUP":/backup ubuntu tar cvf /backup/caddy-data.tar /data
Restore check:
tar tf "$BACKUP/caddy-data.tar" > /dev/null && echo OK
docker run --rm --volumes-from caddy -v "$BACKUP":/backup ubuntu bash -c "cd /data && tar xvf /backup/caddy-data.tar --strip 1"
Sources:
- Caddy docs: Conventions, Data directory: https://caddyserver.com/docs/conventions#data-directory (checked 2026-09-24)
- Docker docs: Volumes, Back up, restore, or migrate data volumes: https://docs.docker.com/engine/storage/volumes/#back-up-restore-or-migrate-data-volumes (checked 2026-09-24)
## Trilium Notes
Trilium copies its own database once a day, once a week, once a month and before each migration into backup/ in the data directory, and the docs encourage "some better backup solution", such as copying the database to another computer. Here that is the whole ./trilium-data folder.
What this compose mounts:
- ./trilium/trilium-data (/home/node/trilium-data in trilium)
BACK UP: document.db (every note, attachment and setting) with its -wal and -shm files, config.ini, and Trilium's own copies in backup/.
1. Stop trilium. document.db is an SQLite database; a copy taken while Trilium writes can catch it half-way. Stopping trilium for the copy avoids that.
docker compose stop trilium
2. Copy while trilium is stopped:
tar czf "$BACKUP/trilium-trilium-data.tar.gz" ./trilium/trilium-data
3. Start it again:
docker compose start trilium
Restore check:
tar tzf "$BACKUP/trilium-trilium-data.tar.gz" > /dev/null && echo OK
Put a copy back (with trilium stopped):
tar xzf "$BACKUP/trilium-trilium-data.tar.gz" # recreates ./trilium/trilium-data; move the old folder aside first
Put ./trilium/trilium-data back, owned by 1000:1000, and run docker compose up -d.
To go back to one of Trilium's own copies instead, the docs: stop Trilium, delete document.db, document.db-wal and document.db-shm, copy backup/backup-weekly.db to document.db, make it writable (chmod 600 document.db) and start Trilium again. With sync set up, do it on every member of the sync cluster.
Sources:
- Trilium docs: Backup (automatic copies, restoring a backup): https://github.com/TriliumNext/Trilium/blob/main/docs/User%20Guide/User%20Guide/Installation%20%26%20Setup/Backup.md (checked 2026-10-01)
- Docker docs: Volumes, Back up, restore, or migrate data volumes: https://docs.docker.com/engine/storage/volumes/#back-up-restore-or-migrate-data-volumes (checked 2026-10-01)
Update it
What docker compose pull does depends only on how each image line in the compose file above is tagged. For Trilium Notes as this page writes it:
| Service | Image | How it is pinned | What docker compose pull does |
|---|---|---|---|
caddy | caddy:2 | Major version only (tag 2) | Takes the newest image tagged 2: minor and patch releases of 2, never 3. A new major version needs a tag edit. |
trilium | triliumnext/trilium:latest | Not pinned: moving tag latest | Moves to the newest image published as latest, which can be a new major version. |
What Trilium Notes's docs say about updating
Trilium's upgrade page: for a Docker server, pull the new image and restart the container. On start Trilium migrates the database, after which older versions cannot read it; it keeps the backup it made before the migration.
- The tag here is latest, so docker compose pull fetches the newest release.
- All members of a sync cluster must speak the same sync protocol version, so upgrade them together.
The steps
- Back up first, as in Back it up above. An update can migrate Trilium Notes's data on its first start; the copy is the way back.
- Download the new images. Running containers are not touched yet:
docker compose pull
- Recreate the containers whose image changed. Volumes and bind-mounted folders stay as they are:
docker compose up -d
- Watch Trilium Notes start (Ctrl+C stops following the log, not the app):
docker compose logs -f trilium
- Optional: remove the old images the pull left without a tag. This covers every stack on the machine, not only this one:
docker image prune
Sources
Every page below was fetched on the date shown.
- Trilium Notes on GitHub (repository description) checked 2026-10-01 (what it does)
- Trilium: docker-compose.yml in the repository (the file the Docker page downloads) checked 2026-10-01 (compose definition and proxy settings)
- Trilium docs: Using Docker (images for AMD64, ARMv7 and ARM64, data directory, user and group IDs) checked 2026-10-01 (compose definition and proxy settings)
- Trilium docs: Trusted proxy (trustedReverseProxy=true) checked 2026-10-01 (compose definition and proxy settings)
- Trilium docs: Configuration (TRILIUM_NETWORK_TRUSTEDREVERSEPROXY) checked 2026-10-01 (compose definition and proxy settings)
- Caddy docs: Keep Caddy running (Docker Compose section) checked 2026-09-23 (Caddy)
- Vaultwarden wiki: Caddy with HTTP challenge (uses the caddy:2 image) checked 2026-09-23 (Caddy)
- Trilium docs: Backup (automatic copies, restoring a backup) checked 2026-10-01 (backup plan)
- Docker docs: Volumes, Back up, restore, or migrate data volumes checked 2026-10-01 (backup plan)
- Caddy docs: Conventions, Data directory checked 2026-09-24 (backup plan)
- Trilium docs: Upgrading TriliumNext checked 2026-10-01 (update notes)
- Docker docs: docker compose pull checked 2026-09-30 (update steps)
- Docker docs: docker compose up (recreates changed containers, keeps volumes) checked 2026-09-30 (update steps)
- Docker docs: docker image prune checked 2026-09-30 (update steps)