Skip to content

fix(docker): catch a volume mounted on the old data path - #12890

Merged
perfectra1n merged 9 commits into
mainfrom
fix/docker-stale-data-dir
Nov 29, 2026
Merged

perfectra1n merged 9 commits into
mainfrom
fix/docker-stale-data-dir

Conversation

@perfectra1n

@perfectra1n perfectra1n commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

A user on Matrix upgraded the Docker image past v0.105 and got the language selection setup screen instead of their notes. They had to go back to v0.105, and after a second attempt they lost about ten days of notes.

This only affects Docker and Kubernetes containers whose volume is mounted at /home/node/.local/share/trilium-data instead of the documented /home/node/trilium-data, or that have no volume at all. A fresh install with the documented mount starts exactly as before, as does anything outside a container.

What was wrong

How Trilium picks its data folder

When the server starts, getTriliumDataDir() picks the data folder by trying four options in order and taking the first one that applies:

/**
* Guards the document of a container against the two ways a volume can miss it. When the document
* is missing but a directory on another mount holds one, the volume is mounted on another path, and
* startup stops instead of creating an empty document. When the document is on the container's own
* filesystem or on tmpfs, it is deleted with the container, so the logs say so at every start.
* Outside a container, `TRILIUM_DATA_DIR` naming a new directory is a deliberate setup.
*/
function checkContainerDocument(dataDirs: { TRILIUM_DATA_DIR: string; DOCUMENT_PATH: string; BACKUP_DIR: string }) {
if (!isInContainer()) {
return;
}
const mounts = readMountTable();
const documentPath = realPath(dataDirs.DOCUMENT_PATH);
const documentDir = realPath(dirname(documentPath));
const documentMount = mounts.find(documentDir);
const appDataDir = getPlatformAppDataDir(os.platform(), process.env.APPDATA);
const oldPathDir = appDataDir ? pathJoin(appDataDir, DIR_NAME) : undefined;
const defaultDirs = [ pathJoin(os.homedir(), DIR_NAME), ...(oldPathDir ? [ oldPathDir ] : []) ];
const other = findOtherDocument(documentDir, documentMount, defaultDirs, mounts);
const onAnotherMount = documentMount && other?.mount && documentMount.id !== other.mount.id;
if (other && onAnotherMount && !fs.existsSync(documentPath)) {
stopStartup(banner("TRILIUM DID NOT START: YOUR DOCUMENT IS ON ANOTHER PATH", [
`There is no document at ${documentPath}, but ${other.dir} holds one, on another mount.`,
"Starting would create a new, empty document instead of opening your notes.",
...(other.dir === oldPathDir ? [
"",
`Docker images up to v0.105 also found a volume mounted at ${other.dir};`,
"newer images do not. If you used v0.106 to v0.108 with this mount, the notes you wrote",
"with them were stored inside that container, not on the volume. If the old container",
"still exists (docker ps -a), stop it and copy the directory holding its document out",
"before removing it:",
" docker stop <old container>",
` docker cp <old container>:${documentDir} ./trilium-data-recent`
] : []),
"",
`To fix this, mount the directory that holds your document at ${documentDir}:`,
` -v /path/on/host:${documentDir}`,
"Or point Trilium at the directory it is in now:",
process.env.TRILIUM_DOCUMENT_PATH
? ` -e TRILIUM_DOCUMENT_PATH=${pathJoin(other.dir, "document.db")}`
: ` -e TRILIUM_DATA_DIR=${other.dir}`,
"",
`To start a new document anyway, stop Trilium and move every file in ${other.dir}`,
"elsewhere together: document.db-wal can hold changes that document.db does not have yet."
]));
}
if (!documentMount || documentMount.kind === "volume") {
return;
}
if (mounts.find(documentPath)?.id === documentPath) {
console.warn(banner("WARNING: PART OF YOUR NOTES IS NOT ON A VOLUME", [
`${documentPath} is mounted on its own, but SQLite keeps document.db-wal next to it, in`,
`${documentDir}, which is inside this container. Changes not yet written back to document.db`,
"are lost if the container is recreated without a clean stop, as is everything else in that",
"directory.",
"",
"To fix this, mount the directory that holds document.db instead of the file:",
` -v /path/on/host:${documentDir}`
]));
return;
}
const usedVolumeDir = other?.mount?.kind === "volume" ? other.dir : undefined;
const unusedVolumeDir = usedVolumeDir
?? defaultDirs.find((dir) => dir !== documentDir && fs.existsSync(dir)
&& mounts.find(dir)?.kind === "volume");
const inMemory = documentMount.kind === "memory";
console.warn(banner("WARNING: YOUR NOTES ARE NOT ON A VOLUME AND WILL BE LOST", [
...(inMemory ? [
`Trilium keeps its document in ${documentDir}, which ${documentMount.id === documentDir
? "is" : `is on ${documentMount.id},`} a tmpfs mount:`,
"its files are kept in memory only and are lost when the container stops."
] : [
`Trilium keeps its document in ${documentDir}, which is not on a volume, so it is`,
"stored inside this container and is deleted when the container is recreated, for",
"example by pulling a new image."
]),
"",
...describeUnusedVolume(usedVolumeDir, unusedVolumeDir, inMemory),
...(inMemory ? [
"If you have notes to keep, save them before the container stops, which clears that",
"directory. docker cp cannot read a tmpfs mount, so make a backup in Trilium",
"(Options > Backup > Backup now), which writes one consistent file, and copy it out:",
` docker exec <this container> tar -C ${dataDirs.BACKUP_DIR} -cf - . > trilium-backup.tar`,
"",
`Then mount a volume at ${documentDir}, with that backup in it as document.db:`
] : [
"If you have notes to keep, stop the container (do not remove it) and copy that whole",
"directory out first, so document.db and document.db-wal are copied together:",
" docker stop <this container>",
` docker cp <this container>:${documentDir} ./trilium-data-recent`,
"",
unusedVolumeDir
? `Then mount that volume at ${documentDir} instead:`
: `Then mount a volume at ${documentDir}:`
]),
` -v /path/on/host:${documentDir}`
]));
}
/** Says which volume the document could have been on, if any. */
function describeUnusedVolume(
usedVolumeDir: string | undefined, unusedVolumeDir: string | undefined, inMemory: boolean
) {
if (usedVolumeDir) {
return [ `${usedVolumeDir} is on a volume and holds an older document that Trilium does not use.` ];
}
if (unusedVolumeDir) {
return [ `A volume is mounted at ${unusedVolumeDir}, which Trilium does not use.` ];
}
return inMemory ? [] : [ "No volume is mounted at that directory or above it." ];
}
/**
* Returns a directory other than `documentDir` that holds a document: a default data directory,
* or one at or directly under a mount point, which is where a volume holds one. One on another
* mount than `documentMount` comes first, since a document on the same mount cannot be a volume
* mounted on the wrong path.
*/
function findOtherDocument(
documentDir: string, documentMount: Mount | undefined, defaultDirs: string[], mounts: MountTable
) {
const mountDirs = mounts.points.flatMap((point) => [ point, pathJoin(point, DIR_NAME) ]);
const found = [ ...defaultDirs, ...mountDirs ]
.map(realPath)
.filter((dir) => dir !== documentDir && fs.existsSync(pathJoin(dir, "document.db")))
.map((dir) => ({ dir, mount: mounts.find(dir) }));
return found.find(({ mount }) => mount?.id !== documentMount?.id) ?? found.at(0);
}
interface Mount {
/** The mount point, or the device number when `/proc/self/mountinfo` cannot be read. */
id: string;
/**
* `root` for the container's own filesystem, deleted with the container; `memory` for tmpfs,
* lost when it stops; `volume` for anything else.
*/
kind: "root" | "memory" | "volume";
}
interface MountTable {
/** The mount points other than `/`, empty when `/proc/self/mountinfo` cannot be read. */
points: string[];
/** Returns the mount holding `path`, or `undefined` when that cannot be told. */
find(path: string): Mount | undefined;
}
const VOLATILE_FILESYSTEMS = new Set([ "tmpfs", "ramfs" ]);
/**
* Reads the mounts of this process from `/proc/self/mountinfo`, which names a bind mount even
* when it comes from the same filesystem as the root. Without it, a path counts as being on
* another mount when its device differs from the root's, which Docker's vfs storage driver defeats.
*/
function readMountTable(): MountTable {
let mounts: ReturnType<typeof parseMountInfo>;
try {
mounts = parseMountInfo(fs.readFileSync("/proc/self/mountinfo", "utf8"));
} catch {
const rootDevice = getDevice("/");
return {
points: [],
find(path) {
const device = getDevice(realPath(path));
if (device === undefined || rootDevice === undefined) {
return undefined;
}
return { id: `device ${device}`, kind: device === rootDevice ? "root" : "volume" };
}
};
}
return {
points: mounts.map(({ point }) => point).filter((point) => point !== "/"),
find(path) {
const target = realPath(path);
let found: (typeof mounts)[number] | undefined;
// A later entry for the same mount point is mounted over the earlier one.
for (const mount of mounts) {
if (isWithin(target, mount.point) && (!found || mount.point.length >= found.point.length)) {
found = mount;
}
}
return found && { id: found.point, kind: getMountKind(found) };
}
};
}
/**
* Parses `/proc/self/mountinfo` into mount points and filesystem types. The mount point is the
* fifth field and the filesystem type the first after the ` - ` separator; the kernel escapes
* space, tab, newline and backslash in paths as three octal digits.
*/
export function parseMountInfo(text: string) {
const mounts: { point: string; fsType: string }[] = [];
for (const line of text.split("\n")) {
const [ fields, separated ] = line.split(" - ");
const point = fields.split(" ")[4];
const fsType = separated?.split(" ")[0];
if (point && fsType) {
mounts.push({
point: point.replace(/\\([0-7]{3})/g,
(_, code: string) => String.fromCharCode(parseInt(code, 8))),
fsType
});
}
}
return mounts;
}
function getMountKind({ point, fsType }: { point: string; fsType: string }): Mount["kind"] {
if (point === "/") {
return "root";
}
return VOLATILE_FILESYSTEMS.has(fsType) ? "memory" : "volume";
}
function isWithin(path: string, dir: string) {
return dir === "/" || path === dir || path.startsWith(`${dir}/`);
}
/** Resolves symlinks in `path`, which might not exist yet, in which case it is returned as is. */
function realPath(path: string) {
try {
return fs.realpathSync(path);
} catch {
return path;
}
}
function getDevice(path: string) {
try {
return fs.statSync(path).dev;
} catch {
return undefined;
}
}

  1. TRILIUM_DATA_DIR, if the variable is set.
  2. ~/trilium-data, if that folder exists.
  3. ~/.local/share/trilium-data on Linux, if ~/.local/share exists. The folder is created if needed.
  4. ~/trilium-data otherwise, created if needed.

Whatever folder it picks, a missing document.db there means a new installation: Trilium creates an empty database and shows the setup screen. Nothing checks whether a database exists somewhere else.

Why the reporter's setup worked up to v0.105

Up to v0.105.0, the standard images (Dockerfile, Dockerfile.alpine, Dockerfile.legacy) did not set TRILIUM_DATA_DIR and did not create any data folder. The docs have always said to mount the volume at /home/node/trilium-data, and that is what most people do. Then step 1 doesn't apply, the mount makes step 2 apply, and Trilium uses the volume.

The reporter mounted their volume at /home/node/.local/share/trilium-data instead. Then step 1 doesn't apply, ~/trilium-data doesn't exist so step 2 doesn't apply either, and Docker creates ~/.local/share as the mount's parent folder, so step 3 applies and picks their volume. That isn't a documented setup, but it worked for years. Anyone who copied a compose file from a desktop install (where the data folder really is ~/.local/share/trilium-data) or from an old guide could have ended up with it.

(The rootless images have set TRILIUM_DATA_DIR since before v0.105, so their users were never affected.)

What changed in v0.106.0 (released 2026-09-25)

8e05dba, from #11164 (merged 2026-08-23), replaced the Node.js healthcheck with a shell script to cut the CPU spike of starting Node.js every minute (#4576). The old Node.js probe found the data folder by copying the same four steps above, ~/.local/share included, so it followed the reporter's volume too. A shell script can't easily do that, so the commit gave it a fixed path by adding this line to all three standard images:

# The healthcheck reads the listening address the server records here.
ENV TRILIUM_DATA_DIR=/home/node/trilium-data

# The healthcheck reads the listening address the server records here.
ENV TRILIUM_DATA_DIR=/home/node/trilium-data

The comment shows the variable was added for the healthcheck. But an ENV line in a Dockerfile applies to every process in the container, the server included. For the server, it is step 1, which overrides the other three. Anyone mounting at /home/node/trilium-data saw no change, because that was already their folder. For the reporter, the server stopped looking at ~/.local/share and used /home/node/trilium-data, which wasn't mounted. That folder had no document.db, so Trilium created a new database there and showed the setup screen.

What changed in v0.107.0 (released 2026-11-08)

dcf9b33, from #11772 (merged 2026-09-29), made the images work under --user by creating the data folder in the image with the right owner:

# A new named volume takes its owner from the mount point, so a container started with --user
# can write to it. Other UIDs need to pass through /home/node to reach a volume of their own.
RUN mkdir -p /home/node/trilium-data && \
chown node:node /home/node/trilium-data && \
chmod 700 /home/node/trilium-data && \
chmod 711 /home/node

That broke the same setup a second way. With ~/trilium-data now in every image, step 2 applies even if TRILIUM_DATA_DIR is unset. Removing the ENV line would no longer bring the old behaviour back.

Why it caused data loss, not just a confusing screen

The new, empty database lived in /home/node/trilium-data, inside the container's own storage, not on the volume. Anyone who set Trilium up again on that screen and kept working put their new notes there. That storage belongs to the container and is deleted whenever the container is recreated. docker compose pull && docker compose up -d, Watchtower and most NAS update buttons all recreate the container. The original notes stayed untouched on the volume, while everything written after the upgrade was wiped at the next update. Nothing in the logs said anything was wrong.

The reporter went back to v0.105.0 (which uses the volume again), upgraded again later and got the empty database again, then tried to recover with backups. They finally found the mismatch by opening a shell in the container, after losing about ten days of notes.

The fix

All of this lives in checkContainerDocument(), which getDataDirs() calls before creating anything. It only runs inside a container: /.dockerenv or /run/.containerenv exists (the same test printListeningUrls() in www.ts uses), or KUBERNETES_SERVICE_HOST is set. Kubernetes needs the variable because containerd, the runtime most clusters use, creates neither file, while Kubernetes sets the variable in every pod. Outside a container, pointing TRILIUM_DATA_DIR at an empty folder is how the "Multiple server instances" docs page tells people to run a second instance, and nothing here should get in the way of that.

/**
* Guards the document of a container against the two ways a volume can miss it. When the document
* is missing but a directory on another mount holds one, the volume is mounted on another path, and
* startup stops instead of creating an empty document. When the document is on the container's own
* filesystem or on tmpfs, it is deleted with the container, so the logs say so at every start.
* Outside a container, `TRILIUM_DATA_DIR` naming a new directory is a deliberate setup.
*/
function checkContainerDocument(dataDirs: { TRILIUM_DATA_DIR: string; DOCUMENT_PATH: string; BACKUP_DIR: string }) {
if (!isInContainer()) {
return;
}
const mounts = readMountTable();
const documentPath = realPath(dataDirs.DOCUMENT_PATH);
const documentDir = realPath(dirname(documentPath));
const documentMount = mounts.find(documentDir);
const appDataDir = getPlatformAppDataDir(os.platform(), process.env.APPDATA);
const oldPathDir = appDataDir ? pathJoin(appDataDir, DIR_NAME) : undefined;
const defaultDirs = [ pathJoin(os.homedir(), DIR_NAME), ...(oldPathDir ? [ oldPathDir ] : []) ];
const other = findOtherDocument(documentDir, documentMount, defaultDirs, mounts);
const onAnotherMount = documentMount && other?.mount && documentMount.id !== other.mount.id;
if (other && onAnotherMount && !fs.existsSync(documentPath)) {
stopStartup(banner("TRILIUM DID NOT START: YOUR DOCUMENT IS ON ANOTHER PATH", [
`There is no document at ${documentPath}, but ${other.dir} holds one, on another mount.`,
"Starting would create a new, empty document instead of opening your notes.",
...(other.dir === oldPathDir ? [
"",
`Docker images up to v0.105 also found a volume mounted at ${other.dir};`,
"newer images do not. If you used v0.106 to v0.108 with this mount, the notes you wrote",
"with them were stored inside that container, not on the volume. If the old container",
"still exists (docker ps -a), stop it and copy the directory holding its document out",
"before removing it:",
" docker stop <old container>",
` docker cp <old container>:${documentDir} ./trilium-data-recent`
] : []),
"",
`To fix this, mount the directory that holds your document at ${documentDir}:`,
` -v /path/on/host:${documentDir}`,
"Or point Trilium at the directory it is in now:",
process.env.TRILIUM_DOCUMENT_PATH
? ` -e TRILIUM_DOCUMENT_PATH=${pathJoin(other.dir, "document.db")}`
: ` -e TRILIUM_DATA_DIR=${other.dir}`,
"",
`To start a new document anyway, stop Trilium and move every file in ${other.dir}`,
"elsewhere together: document.db-wal can hold changes that document.db does not have yet."
]));
}
if (!documentMount || documentMount.kind === "volume") {
return;
}
if (mounts.find(documentPath)?.id === documentPath) {
console.warn(banner("WARNING: PART OF YOUR NOTES IS NOT ON A VOLUME", [
`${documentPath} is mounted on its own, but SQLite keeps document.db-wal next to it, in`,
`${documentDir}, which is inside this container. Changes not yet written back to document.db`,
"are lost if the container is recreated without a clean stop, as is everything else in that",
"directory.",
"",
"To fix this, mount the directory that holds document.db instead of the file:",
` -v /path/on/host:${documentDir}`
]));
return;
}
const usedVolumeDir = other?.mount?.kind === "volume" ? other.dir : undefined;
const unusedVolumeDir = usedVolumeDir
?? defaultDirs.find((dir) => dir !== documentDir && fs.existsSync(dir)
&& mounts.find(dir)?.kind === "volume");
const inMemory = documentMount.kind === "memory";
console.warn(banner("WARNING: YOUR NOTES ARE NOT ON A VOLUME AND WILL BE LOST", [
...(inMemory ? [
`Trilium keeps its document in ${documentDir}, which ${documentMount.id === documentDir
? "is" : `is on ${documentMount.id},`} a tmpfs mount:`,
"its files are kept in memory only and are lost when the container stops."
] : [
`Trilium keeps its document in ${documentDir}, which is not on a volume, so it is`,
"stored inside this container and is deleted when the container is recreated, for",
"example by pulling a new image."
]),
"",
...describeUnusedVolume(usedVolumeDir, unusedVolumeDir, inMemory),
...(inMemory ? [
"If you have notes to keep, save them before the container stops, which clears that",
"directory. docker cp cannot read a tmpfs mount, so make a backup in Trilium",
"(Options > Backup > Backup now), which writes one consistent file, and copy it out:",
` docker exec <this container> tar -C ${dataDirs.BACKUP_DIR} -cf - . > trilium-backup.tar`,
"",
`Then mount a volume at ${documentDir}, with that backup in it as document.db:`
] : [
"If you have notes to keep, stop the container (do not remove it) and copy that whole",
"directory out first, so document.db and document.db-wal are copied together:",
" docker stop <this container>",
` docker cp <this container>:${documentDir} ./trilium-data-recent`,
"",
unusedVolumeDir
? `Then mount that volume at ${documentDir} instead:`
: `Then mount a volume at ${documentDir}:`
]),
` -v /path/on/host:${documentDir}`
]));
}
/** Says which volume the document could have been on, if any. */
function describeUnusedVolume(
usedVolumeDir: string | undefined, unusedVolumeDir: string | undefined, inMemory: boolean
) {
if (usedVolumeDir) {
return [ `${usedVolumeDir} is on a volume and holds an older document that Trilium does not use.` ];
}
if (unusedVolumeDir) {
return [ `A volume is mounted at ${unusedVolumeDir}, which Trilium does not use.` ];
}
return inMemory ? [] : [ "No volume is mounted at that directory or above it." ];
}
/**
* Returns a directory other than `documentDir` that holds a document: a default data directory,
* or one at or directly under a mount point, which is where a volume holds one. One on another
* mount than `documentMount` comes first, since a document on the same mount cannot be a volume
* mounted on the wrong path.
*/
function findOtherDocument(
documentDir: string, documentMount: Mount | undefined, defaultDirs: string[], mounts: MountTable
) {
const mountDirs = mounts.points.flatMap((point) => [ point, pathJoin(point, DIR_NAME) ]);
const found = [ ...defaultDirs, ...mountDirs ]
.map(realPath)
.filter((dir) => dir !== documentDir && fs.existsSync(pathJoin(dir, "document.db")))
.map((dir) => ({ dir, mount: mounts.find(dir) }));
return found.find(({ mount }) => mount?.id !== documentMount?.id) ?? found.at(0);
}
interface Mount {
/** The mount point, or the device number when `/proc/self/mountinfo` cannot be read. */
id: string;
/**
* `root` for the container's own filesystem, deleted with the container; `memory` for tmpfs,
* lost when it stops; `volume` for anything else.
*/
kind: "root" | "memory" | "volume";
}
interface MountTable {
/** The mount points other than `/`, empty when `/proc/self/mountinfo` cannot be read. */
points: string[];
/** Returns the mount holding `path`, or `undefined` when that cannot be told. */
find(path: string): Mount | undefined;
}
const VOLATILE_FILESYSTEMS = new Set([ "tmpfs", "ramfs" ]);
/**
* Reads the mounts of this process from `/proc/self/mountinfo`, which names a bind mount even
* when it comes from the same filesystem as the root. Without it, a path counts as being on
* another mount when its device differs from the root's, which Docker's vfs storage driver defeats.
*/
function readMountTable(): MountTable {
let mounts: ReturnType<typeof parseMountInfo>;
try {
mounts = parseMountInfo(fs.readFileSync("/proc/self/mountinfo", "utf8"));
} catch {
const rootDevice = getDevice("/");
return {
points: [],
find(path) {
const device = getDevice(realPath(path));
if (device === undefined || rootDevice === undefined) {
return undefined;
}
return { id: `device ${device}`, kind: device === rootDevice ? "root" : "volume" };
}
};
}
return {
points: mounts.map(({ point }) => point).filter((point) => point !== "/"),
find(path) {
const target = realPath(path);
let found: (typeof mounts)[number] | undefined;
// A later entry for the same mount point is mounted over the earlier one.
for (const mount of mounts) {
if (isWithin(target, mount.point) && (!found || mount.point.length >= found.point.length)) {
found = mount;
}
}
return found && { id: found.point, kind: getMountKind(found) };
}
};
}
/**
* Parses `/proc/self/mountinfo` into mount points and filesystem types. The mount point is the
* fifth field and the filesystem type the first after the ` - ` separator; the kernel escapes
* space, tab, newline and backslash in paths as three octal digits.
*/
export function parseMountInfo(text: string) {
const mounts: { point: string; fsType: string }[] = [];
for (const line of text.split("\n")) {
const [ fields, separated ] = line.split(" - ");
const point = fields.split(" ")[4];
const fsType = separated?.split(" ")[0];
if (point && fsType) {
mounts.push({
point: point.replace(/\\([0-7]{3})/g,
(_, code: string) => String.fromCharCode(parseInt(code, 8))),
fsType
});
}
}
return mounts;
}
function getMountKind({ point, fsType }: { point: string; fsType: string }): Mount["kind"] {
if (point === "/") {
return "root";
}
return VOLATILE_FILESYSTEMS.has(fsType) ? "memory" : "volume";
}
function isWithin(path: string, dir: string) {
return dir === "/" || path === dir || path.startsWith(`${dir}/`);
}
/** Resolves symlinks in `path`, which might not exist yet, in which case it is returned as is. */
function realPath(path: string) {
try {
return fs.realpathSync(path);
} catch {
return path;
}
}
function getDevice(path: string) {
try {
return fs.statSync(path).dev;
} catch {
return undefined;
}
}

What it looks at

  • The folder that holds the document, not TRILIUM_DATA_DIR. That is the parent of DOCUMENT_PATH with symlinks resolved, so TRILIUM_DOCUMENT_PATH and a symlinked data folder are judged by where the database really is.
  • Which mount that folder is on, read from /proc/self/mountinfo, which lists every bind mount even when it comes from the same filesystem as the container's root (Docker's vfs storage driver does that). Each mount is one of three kinds: the container's own root filesystem (deleted with the container), tmpfs/ramfs (lost when it stops), or a volume. If /proc can't be read, it falls back to comparing device numbers with /. Folders are compared, not files, because overlayfs can report the device of its underlying layer for a regular file. When it can't tell at all, it stays quiet.

When it stops startup

There is no document at DOCUMENT_PATH, another folder holds one, and that folder is on a different mount from where the new document would go. The other folders it checks are ~/trilium-data, ~/.local/share/trilium-data, and every mount point plus its trilium-data subfolder, so a volume holding a document at any path is found. A document on a different mount comes first, so one on the same mount (such as ~/trilium-data on a volume at /home/node) can't hide a separate volume at the old path.

The "different mount" condition is what separates the reporter's case (new document in container storage, old one on a volume) from a deliberate setup. In toolbox or distrobox (Podman, so /run/.containerenv exists), the home folder is one bind mount, and a second instance or a dev server with TRILIUM_DATA_DIR pointing at a new folder has to keep starting even though ~/.local/share/trilium-data holds the desktop document.

The message names both paths, the volume mount that fixes it, and the variable that keeps the current layout working: TRILIUM_DOCUMENT_PATH if the user set that, TRILIUM_DATA_DIR otherwise. Only for the old ~/.local/share path does it add the v0.105 history and the docker stop then docker cp steps for notes written on v0.106 to v0.108. For anyone who really wants a new document, it says to move every file in the other folder together, because after a crash document.db-wal can still hold saved changes that document.db doesn't have yet.

When it warns (at every start)

The document's folder is Warning
on the container's own filesystem The notes are deleted when the container is recreated. It names what it can see: a volume that holds an older document Trilium doesn't use (the reporter's in-between state), a volume mounted at a default path Trilium doesn't use (a new user who copied an old guide), or no volume at all. Then docker stop and docker cp of that folder, and the -v that fixes it.
on tmpfs The notes are lost when the container stops, and docker cp can't read a tmpfs mount, so it says to make a backup in Trilium (Options > Backup > Backup now, one consistent file through SQLite's backup API), copy the backup directory out with docker exec … tar, mount an empty volume, and restore the file from the setup screen's Restore from backup, which takes .db and .tnbackup files (compressed or encrypted backups are .tnbackup, which renaming to document.db would not open).
on the container's filesystem, but document.db is bind-mounted as a single file The file survives, but SQLite keeps document.db-wal next to it, inside the container, along with everything else in that folder. Mount the folder instead.

Stays quiet

Fresh installs with the documented mount, TRILIUM_DATA_DIR=/data with a volume at /data (as the Kubernetes charts on kubesearch.dev set it, including a subPath mount and readOnlyRootFilesystem with a memory-backed /tmp), a volume at /home/node, the documented mount with the old path still mounted alongside, toolbox and distrobox, a symlinked data folder, anything it can't inspect, and anything outside a container. The spec covers each of these.

CI's Docker smoke test runs the image without a volume, so it now prints the warning, but it only checks the health status and still passes.

I considered removing the ENV line from the images instead. That isn't enough on its own, because the image now also creates ~/trilium-data, which takes priority over ~/.local/share for the same reason. The healthcheck also relies on the variable.

Warning users before they upgrade

The log messages can't reach the users who are most at risk. Upgrading to the release that has this fix means pulling a new image, which recreates the container and deletes the notes stored in it before the new code ever runs. So the warning also goes where they will see it before upgrading:

  • A type: warning changelog entry. It renders as a [!WARNING] admonition at the top of the release note, and of the nightly release body until then, telling users with the old mount path to run docker cp before pulling.
  • The Docker installation page now has a warning, not a note, explaining the old mount path, what v0.106 to v0.108 did with it, and how to save the notes. The volume instructions above it now also say that notes without a volume are deleted with the container, and that Trilium warns about it.

There are also two regular changelog entries: a fix for the startup check, and an improvement for the warning about notes that aren't on a volume.

A user upgrading the Docker image from v0.105 got the setup screen
instead of their notes. Their volume was mounted at
/home/node/.local/share/trilium-data. Until v0.106 the image left
TRILIUM_DATA_DIR unset, so getTriliumDataDir() fell through to the
platform app data directory and found that mount. Since 8e05dba the
image sets TRILIUM_DATA_DIR=/home/node/trilium-data (and since
dcf9b33 it also creates that directory), so Trilium created a new
document in the container's own, unmounted directory. Notes written
there were lost the next time the container was recreated.

getDataDirs() now checks, before anything is created, whether the data
directory lacks document.db while ~/trilium-data or the platform app
data directory holds one. If so, startup stops with a message naming
both paths, the mount that fixes it and the TRILIUM_DATA_DIR that keeps
the old path.

The check runs only in a container (/.dockerenv or
/run/.containerenv, as printListeningUrls() detects it). Outside one,
pointing TRILIUM_DATA_DIR at an empty directory is the documented way
to run a second instance, so checking there would block that setup.
Removing the ENV from the image was rejected: the image also creates
~/trilium-data now, which wins over ~/.local/share in the same way.

A container that already ran a newer image with the old mount has a
document in /home/node/trilium-data, so the check lets it start; it
recovers once the container is recreated.

The spec that expects the stop failed with the call disabled and passes
with it.

Assisted-by: Claude Code
@github-actions

Copy link
Copy Markdown
Contributor

📚 Documentation preview is ready!

🔗 Preview URL: https://pr-12890.trilium-docs.pages.dev
📖 Production URL: https://docs.triliumnotes.org

✅ All checks passed

This preview will be updated automatically with new commits.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; the revised recovery advice addresses the remaining backup-format finding.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the revised recovery advice addresses the remaining backup-format finding.

Summary

This PR catches misplaced container volumes before Trilium creates an empty document.

  • Container startup stops when another mount holds the document.
  • Container startup warns when notes are not stored on a lasting volume.

perfectra1n intentionally left early startup messages in English because no database locale is available. Greptile accepted that exception.

Reviews (7) · Last reviewed commit: "fix(docker): restore tmpfs backups throu..." · Reviewed by Greptile

Comment thread apps/server/src/services/data_dir.ts Resolved
Comment thread apps/server/src/services/data_dir.ts Outdated
Comment on lines +138 to +141
`Trilium cannot start because its data directory, ${dataDir}, holds no document, but ${otherDir} does.`,
"",
"Starting would create a new, empty document instead of opening that one. Docker images up to",
`v0.105 used ${otherDir} when a volume was mounted there; newer images use ${dataDir}.`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Recovery guidance stays English

The new startup explanation is hardcoded English. CLAUDE.md requires user-facing text, including server messages, to use translations. Put this explanation in the server catalogue while keeping it available before normal translation setup runs. This repository requirement must be satisfied before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this one can be translated, so I've left it in English on purpose:

  • The server's language is the locale option, which lives in document.db. This message runs exactly when the data directory has no document.db, so there is no language to read, and i18next would fall back to English anyway.
  • getDataDirs() runs synchronously when data_dir.ts is first loaded, before the database is opened. Setting up i18next is asynchronous and reads the locale from that database, so it can't run first.
  • The other startup errors in this file, the permission messages from checkExistingEntries() and describePermissionError(), are English for the same reasons.

Leaving this thread open for a maintainer to decide.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right. This check runs before there’s a database locale to use or i18next is initialized, so requiring translation here would not make the message meaningfully translatable. The existing English-only startup errors in this file support treating this as the same constraint. I agree this isn’t an actionable finding for this change.

A rule I could remember is: “Startup errors emitted before the database and i18next are initialized may remain in English when no locale is available.” Would you like me to save that for future reviews?

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 2.48kB (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
client-esm 44.54MB 2.48kB (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: standalone-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/src-*.js 2.32MB 2.32MB 139916.55% ⚠️
assets/src-*.js -2.32MB 1.66kB -99.93%
src/src-*.js -73 bytes 193 bytes -27.44%
src/src-*.js 9 bytes 266 bytes 3.5%
src/src-*.js 64 bytes 257 bytes 33.16% ⚠️
assets/html-*.js -312.81kB 2.78kB -99.12%
assets/html-*.js 312.81kB 315.59kB 11248.22% ⚠️
assets/dist-*.js -240.53kB 3.8kB -98.44%
assets/dist-*.js -4.13kB 27.26kB -13.17%
assets/dist-*.js -1.29kB 2.61kB -33.06%
assets/dist-*.js 66.93kB 85.33kB 363.87% ⚠️
assets/dist-*.js 11.81kB 15.47kB 322.85% ⚠️
assets/dist-*.js -90.6kB 13.59kB -86.95%
assets/dist-*.js -152.02kB 32.66kB -82.32%
assets/dist-*.js 143.57kB 147.52kB 3635.73% ⚠️
assets/dist-*.js 32 bytes 3.75kB 0.86%
assets/dist-*.js -52 bytes 3.91kB -1.31%
assets/dist-*.js -120.51kB 27.02kB -81.69%
assets/dist-*.js -94.74kB 3.84kB -96.1%
assets/dist-*.js -118 bytes 3.67kB -3.11%
assets/dist-*.js 225.84kB 229.84kB 5657.39% ⚠️
assets/dist-*.js -69 bytes 3.79kB -1.79%
assets/dist-*.js 10 bytes 3.96kB 0.25%
assets/dist-*.js -281.23kB 3.88kB -98.64%
assets/dist-*.js 17.34kB 21.48kB 418.79% ⚠️
assets/dist-*.js -3.89kB 3.95kB -49.61%
assets/dist-*.js 7.89kB 11.59kB 213.21% ⚠️
assets/dist-*.js 4.0kB 7.84kB 103.93% ⚠️
assets/dist-*.js -41.62kB 3.78kB -91.67%
assets/dist-*.js 41.45kB 45.4kB 1051.36% ⚠️
assets/dist-*.js -28.72kB 3.94kB -87.93%
assets/dist-*.js 1.18kB 3.92kB 42.94% ⚠️
assets/dist-*.js -23.39kB 3.88kB -85.78%
assets/dist-*.js 36.49kB 40.48kB 915.43% ⚠️
assets/dist-*.js -11.76kB 3.71kB -76.05%
assets/dist-*.js -27.48kB 16.96kB -61.83%
assets/dist-*.js 5.07kB 8.82kB 135.28% ⚠️
assets/dist-*.js -13.3kB 3.66kB -78.44%
assets/dist-*.js 14.64kB 18.47kB 382.39% ⚠️
assets/dist-*.js -1.34kB 3.99kB -25.2%
assets/dist-*.js 67.12kB 71.03kB 1717.63% ⚠️
assets/dist-*.js -226.01kB 3.83kB -98.33%
assets/dist-*.js 214.08kB 285.11kB 301.38% ⚠️
assets/dist-*.js -12.85kB 3.71kB -77.58%
assets/dist-*.js 8.08kB 11.89kB 212.51% ⚠️
assets/dist-*.js -1.21kB 2.82kB -30.11%
assets/dist-*.js -81.27kB 4.06kB -95.24%
assets/dist-*.js 234 bytes 3.94kB 6.32% ⚠️
assets/dist-*.js 180.96kB 184.68kB 4863.21% ⚠️
assets/dist-*.js 27.52kB 31.4kB 708.78% ⚠️
assets/dist-*.js 232.44kB 244.33kB 1955.26% ⚠️
assets/dist-*.js -19.27kB 21.21kB -47.6%
assets/dist-*.js 15.39kB 28.99kB 113.27% ⚠️
assets/dist-*.js 2.51kB 5.33kB 89.11% ⚠️
assets/dist-*.js 275 bytes 3.95kB 7.49% ⚠️
assets/dist-*.js -19.44kB 3.9kB -83.29%
assets/dist-*.js -23.16kB 3.86kB -85.71%
assets/dist-*.js 10.65kB 14.59kB 270.47% ⚠️
assets/dist-*.js -4.9kB 3.91kB -55.6%
assets/dist-*.js 19.41kB 23.34kB 494.65% ⚠️
assets/dist-*.js 40.76kB 44.44kB 1108.92% ⚠️
assets/dist-*.js 14.34kB 18.39kB 353.3% ⚠️
assets/dist-*.js -17.07kB 4.14kB -80.48%
assets/dist-*.js 1.38kB 3.99kB 52.95% ⚠️
assets/dist-*.js -26.24kB 2.75kB -90.53%
assets/dist-*.js -238 bytes 3.68kB -6.08%
assets/dist-*.js 12.72kB 16.57kB 330.23% ⚠️
assets/dist-*.js -14.77kB 3.7kB -79.96%
assets/dist-*.js -7.56kB 4.03kB -65.22%
assets/dist-*.js -10.74kB 3.85kB -73.61%
assets/dist-*.js 100.31kB 104.19kB 2587.36% ⚠️
assets/dist-*.js 77.11kB 98.58kB 359.0% ⚠️
assets/dist-*.js -60 bytes 3.72kB -1.59%
src/dist-*.js 1 bytes 42 bytes 2.44%
src/dist-*.js -6 bytes 42 bytes -12.5%
src/dist-*.js 18 bytes 60 bytes 42.86% ⚠️
src/dist-*.js 6 bytes 48 bytes 14.29% ⚠️
src/dist-*.js -19 bytes 41 bytes -31.67%
assets/sql-*.js 31.34kB 37.01kB 552.27% ⚠️
assets/sql-*.js -31.34kB 5.67kB -84.67%
assets/javascript-*.js 10.61kB 17.04kB 164.95% ⚠️
assets/javascript-*.js -10.61kB 6.43kB -62.26%
assets/clojure-*.js -5.33kB 4.2kB -55.94%
assets/clojure-*.js 5.33kB 9.52kB 126.98% ⚠️
assets/verilog-*.js -3.4kB 5.2kB -39.54%
assets/verilog-*.js 3.4kB 8.6kB 65.41% ⚠️
assets/local-*.js 4.14kB 8.25kB 100.51% ⚠️
assets/local-*.js -4.14kB 4.12kB -50.13%
assets/swift-*.js -4.32kB 3.87kB -52.75%
assets/swift-*.js 4.32kB 8.19kB 111.63% ⚠️
assets/erlang-*.js -5.43kB 2.54kB -68.08%
assets/erlang-*.js 5.43kB 7.97kB 213.29% ⚠️
assets/mirc-*.js -1.6kB 5.99kB -21.06%
assets/mirc-*.js 1.6kB 7.58kB 26.67% ⚠️
assets/nsis-*.js -977 bytes 6.16kB -13.69%
assets/nsis-*.js 977 bytes 7.14kB 15.86% ⚠️
assets/scheme-*.js -3.17kB 3.34kB -48.64%
assets/scheme-*.js 3.17kB 6.51kB 94.71% ⚠️
assets/cobol-*.js 2.23kB 6.31kB 54.89% ⚠️
assets/cobol-*.js -2.23kB 4.07kB -35.44%
assets/xquery-*.js 875 bytes 6.25kB 16.26% ⚠️
assets/xquery-*.js -875 bytes 5.38kB -13.99%
assets/julia-*.js 1.81kB 5.4kB 50.45% ⚠️
assets/julia-*.js -1.81kB 3.59kB -33.53%
assets/ruby-*.js -1.3kB 3.87kB -25.18%
assets/ruby-*.js 1.3kB 5.17kB 33.65% ⚠️
assets/crystal-*.js 1.47kB 5.12kB 40.38% ⚠️
assets/crystal-*.js -1.47kB 3.65kB -28.77%
assets/haskell-*.js -2.04kB 2.2kB -48.17%
assets/haskell-*.js 2.04kB 4.24kB 92.95% ⚠️
assets/livescript-*.js -879 bytes 3.27kB -21.19%
assets/livescript-*.js 879 bytes 4.15kB 26.88% ⚠️
assets/q-*.js -2.58kB 1.19kB -68.41%
assets/q-*.js 2.58kB 3.77kB 216.53% ⚠️
assets/cypher-*.js -1.5kB 1.81kB -45.23%
assets/cypher-*.js 1.5kB 3.31kB 82.59% ⚠️
assets/lua-*.js 1.27kB 3.22kB 65.26% ⚠️
assets/lua-*.js -1.27kB 1.95kB -39.49%
assets/r-*.js -31 bytes 2.97kB -1.03%
assets/r-*.js 31 bytes 3.0kB 1.04%
assets/rust-*.js 641 bytes 2.82kB 29.43% ⚠️
assets/rust-*.js -641 bytes 2.18kB -22.74%
assets/cmake-*.js 1.73kB 2.55kB 210.84% ⚠️
assets/cmake-*.js -1.73kB 821 bytes -67.83%
assets/smalltalk-*.js -1.41kB 666 bytes -67.95%
assets/smalltalk-*.js 1.41kB 2.08kB 212.01% ⚠️
assets/ebnf-*.js 1.62kB 2.05kB 382.12% ⚠️
assets/ebnf-*.js -1.62kB 425 bytes -79.26%
assets/en-*.js -695 bytes 603 bytes -53.54%
assets/en-*.js 695 bytes 1.3kB 115.26% ⚠️
assets/http-*.js -46 bytes 865 bytes -5.05%
assets/http-*.js 46 bytes 911 bytes 5.32% ⚠️
assets/protobuf-*.js 167 bytes 902 bytes 22.72% ⚠️
assets/protobuf-*.js -167 bytes 735 bytes -18.51%
assets/properties-*.js -129 bytes 601 bytes -17.67%
assets/properties-*.js 129 bytes 730 bytes 21.46% ⚠️
assets/diff-*.js -275 bytes 370 bytes -42.64%
assets/diff-*.js 275 bytes 645 bytes 74.32% ⚠️
assets/__vite-*.js 74 bytes 184 bytes 67.27% ⚠️
assets/__vite-*.js -74 bytes 110 bytes -40.22%
view changes for bundle: client-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
src/script-*.desktop-3PkvmvDF.js (New) 507.64kB 507.64kB 100.0% 🚀
src/launch-*.desktop.mobile-EMqrRnAS.js (New) 396.87kB 396.87kB 100.0% 🚀
src/right-*.desktop-D4PGRNWi.js (New) 171.6kB 171.6kB 100.0% 🚀
src/shell.desktop.mobile.login.setup.set_password.print-*.js 162 bytes 154.78kB 0.1%
src/dist-*.js 11 bytes 10.14kB 0.11%
src/dist-*.js -41 bytes 42 bytes -49.4%
src/dist-*.js 7 bytes 48 bytes 17.07% ⚠️
src/dist-*.js 54 bytes 26.98kB 0.2%
src/dist-*.js -1 bytes 41 bytes -2.38%
src/dist-*.js 35 bytes 83 bytes 72.92% ⚠️
src/status-*.desktop_launch-bar.mobile-Bm3L0cvp.js (New) 66.96kB 66.96kB 100.0% 🚀
src/status-*.desktop-BzTbs5-f.js (New) 62.49kB 62.49kB 100.0% 🚀
src/launch-*.desktop.mobile_shell.setup-B4ldfX7v.js (New) 9.14kB 9.14kB 100.0% 🚀
src/script-*.desktop_shell.login.setup.set_password-B1GAFRkY.js (New) 4.87kB 4.87kB 100.0% 🚀
src/script-*.desktop-DmuK0xx7.js (New) 3.9kB 3.9kB 100.0% 🚀
src/shell.desktop.print_launch-*.mobile-TfVF-dOg.js (New) 3.59kB 3.59kB 100.0% 🚀
src/status-*.desktop_shell.login.setup.set_password-CANeFcRp.js (New) 1.93kB 1.93kB 100.0% 🚀
src/script-*.desktop_shell.setup-D_C2E68t.js (New) 1.21kB 1.21kB 100.0% 🚀
src/status-*.desktop_launch-bar.mobile_shell.login.setup.set_password-B0aNvGuQ.js (New) 854 bytes 854 bytes 100.0% 🚀
src/launch-*.desktop.mobile_shell.login.setup.set_password-AXhGmiNR.js (New) 789 bytes 789 bytes 100.0% 🚀
src/script-*.desktop-hbC4m7GK.js (Deleted) -507.64kB 0 bytes -100.0% 🗑️
src/launch-*.desktop.mobile-fzov8ENK.js (Deleted) -394.62kB 0 bytes -100.0% 🗑️
src/right-*.desktop-D1BiWAc9.js (Deleted) -171.6kB 0 bytes -100.0% 🗑️
src/status-*.desktop_launch-bar.mobile-OPgAi0Kf.js (Deleted) -66.96kB 0 bytes -100.0% 🗑️
src/status-*.desktop-DvDPqDsP.js (Deleted) -62.49kB 0 bytes -100.0% 🗑️
src/launch-*.desktop.mobile_shell.setup-aakicP8v.js (Deleted) -9.14kB 0 bytes -100.0% 🗑️
src/script-*.desktop_shell.login.setup.set_password-DeA9GzeD.js (Deleted) -4.87kB 0 bytes -100.0% 🗑️
src/script-*.desktop-C4D5YCgK.js (Deleted) -3.9kB 0 bytes -100.0% 🗑️
src/shell.desktop.print_launch-*.mobile-DZkUWX7j.js (Deleted) -3.59kB 0 bytes -100.0% 🗑️
src/status-*.desktop_shell.login.setup.set_password-DfEJ0Hhm.js (Deleted) -1.93kB 0 bytes -100.0% 🗑️
src/script-*.desktop_shell.setup-sb48kR-2.js (Deleted) -1.21kB 0 bytes -100.0% 🗑️
src/status-*.desktop_launch-bar.mobile_shell.login.setup.set_password-7cVWBoc3.js (Deleted) -854 bytes 0 bytes -100.0% 🗑️
src/launch-*.desktop.mobile_shell.login.setup.set_password-D78q7X6x.js (Deleted) -789 bytes 0 bytes -100.0% 🗑️

@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Images v0.106 to v0.108 ignored a volume mounted at
/home/node/.local/share/trilium-data and stored new notes in
/home/node/trilium-data inside the container. Recreating the container,
which pulling a new image does, deletes them. The startup check alone
cannot reach those users: by the time they run it, the upgrade has
already recreated the container.

So the warning goes where they will see it before upgrading:

- A `type: warning` changelog entry, which renders as an admonition at
  the top of the release note and the nightly release body, with the
  `docker cp` that saves the notes.
- The Docker installation page, as a warning instead of a note.

In the container logs, checkForDocumentElsewhere() now prints both
messages as banners. The stop also says that notes written on v0.106
to v0.108 can still be in the old container and how to copy them out.
When both directories hold a document and the data directory is not a
mount point (its device equals its parent's), startup goes on but
warns that the open document is deleted with the container. The mount
point test keeps the warning off a setup that copied its data to the
new mount and left the old one in place.

The warning spec failed with the warning disabled and passes with it.

Assisted-by: Claude Code (Claude Opus 5.5)
Comment thread apps/server/src/services/data_dir.ts Resolved
The stop banner told users who want a new document to move
document.db out of the old directory. After a crash or a forced stop,
saved changes can still be in document.db-wal, so moving the database
alone leaves them behind and the moved copy opens without them. The
banner now says to stop Trilium and move every file in the directory
together.

The `docker cp` advice in both banners, the release note warning and
the Docker page copied the data directory of a container that could be
running, so document.db and document.db-wal could come from different
moments. Each now stops the container first, without removing it, and
copies the whole directory.

The updated specs failed against the previous banners on the missing
`docker stop` and pass with them.

Assisted-by: Claude Code (Claude Opus 5.5)
The warning that the open document is deleted with the container
decided that by comparing the data directory's device with its
parent's, which only detects a volume mounted at the data directory
itself. With a volume at /home/node, which holds both default data
directories, the two share a device, so Trilium warned that safe notes
would be lost and told the user to change a mount that works.

isOnVolume() now compares the data directory's device with the root
filesystem's instead, which tells the container's own files from a
volume mounted at the directory or any of its ancestors. It compares
directories because overlayfs can report the device of its underlying
layer for a regular file, so stat on document.db would not answer the
same question.

The spec's new case, a volume at /home/node, failed against the parent
comparison and passes with this.

Assisted-by: Claude Code (Claude Opus 5.5)
The warning that the open document is deleted with the container only
fired when another default data directory also held a document. A new
user who mounts a volume at the old ~/.local/share/trilium-data path
gets no document there, so Trilium created one in the container's own
/home/node/trilium-data and stayed silent at every later start, until
an image update deleted it. The same goes for a container started with
no volume at all.

checkContainerDataDir() (renamed from checkForDocumentElsewhere(), as it
now covers more than a second document) warns at every start whenever
the data directory is not on a volume. The banner names what to fix:
the volume that holds an older document, a volume mounted on a path
Trilium does not use, or no volume at all, with the -v that fixes it.
The stop for a data directory with no document while the old path has
one is unchanged.

isInContainer() also accepts KUBERNETES_SERVICE_HOST. containerd, the
runtime of most Kubernetes clusters, creates neither /.dockerenv nor
/run/.containerenv, so neither check ran in a pod. Kubernetes sets the
variable in every pod, and nothing sets it outside one.

CI's Docker smoke test runs the image without a volume, so it now
prints the warning; it only checks the health status, so it still
passes.

The new specs, Kubernetes detection and the warning for a fresh install
with the volume on the old path or with none, failed against the
previous checks and pass with these.

Assisted-by: Claude Code (Claude Opus 5.5)
The server suite failed its 100% coverage threshold on this branch:
no spec reached the catch in isOnVolume(), which treats a data
directory that cannot be inspected as being on a volume, so Trilium
stays quiet rather than warn on a guess. Run alone, the spec also
missed the branch for a platform with no app data directory, where
only ~/trilium-data is checked.

The quiet-start spec now covers both, and data_dir.spec.ts alone
brings data_dir.ts to 100% of lines, statements, functions and
branches.

The other gap in the same run, lines 52-53 of sqlite_binding.ts, comes
from 9c19cb6 on main, whose own Dev run fails on it, and is not
part of this branch.

Assisted-by: Claude Code (Claude Opus 5.5)
Comment thread apps/server/src/services/data_dir.ts Resolved
@perfectra1n perfectra1n changed the title fix(docker): stop instead of starting on an empty document fix(docker): catch a volume mounted on the old data path Nov 29, 2026
The container check judged TRILIUM_DATA_DIR and compared device
numbers, which got several setups wrong:

- TRILIUM_DOCUMENT_PATH can put document.db outside the data
  directory, so a document off every volume went unreported, a safe
  one was reported as lost, and the advice copied a directory without
  it. The check now judges and copies the directory holding
  DOCUMENT_PATH, symlinks resolved, and suggests TRILIUM_DOCUMENT_PATH
  when that is what the user set.
- A toolbox or distrobox container (Podman, so /run/.containerenv)
  bind-mounts the home directory. A second instance or a dev server
  there, with TRILIUM_DATA_DIR on a new directory while
  ~/.local/share/trilium-data holds the desktop document, could not
  start. The stop now requires the other document to be on another
  mount than the one the new document would go on, which is the
  reporter's case (container storage against a volume) and not this.
- Docker's vfs storage driver, or a bind mount from the root's own
  filesystem, gives a volume the root's device number, so a correct
  mount drew a warning that the notes will be lost. Mounts are now
  read from /proc/self/mountinfo, which names every bind mount; the
  device comparison remains only for when it cannot be read.
- A volume mounted at a path Trilium never looks at (/data, a copied
  path from another image) holding document.db led to the setup
  screen. Mount points and their trilium-data subdirectories are now
  searched too, and the v0.105 history is given only for the old
  path, where it is true.
- A tmpfs data directory counted as a volume. It is now reported as
  lost when the container stops, with the copy taken before stopping,
  since stopping clears it.
- document.db bind-mounted as a single file was reported as lost. The
  file survives, but SQLite keeps document.db-wal beside it, inside
  the container, so it now gets its own warning: mount the directory.

Unchanged and covered by the spec: fresh installs, the documented
mount, TRILIUM_DATA_DIR=/data with a volume there as Kubernetes charts
set it, a read-only root with a tmpfs /tmp, a volume at /home/node,
and anything outside a container.

Against the previous check, 8 of the 10 new container specs fail,
among them the toolbox case, which exited. The two that pass guard
behaviour the previous check already had. data_dir.spec.ts alone
covers 100% of data_dir.ts.

Assisted-by: Claude Code (Claude Opus 5.5)
Comment thread apps/server/src/services/data_dir.ts Resolved
Comment thread apps/server/src/services/data_dir.ts Resolved
The warning for a document on tmpfs said to copy the directory with
docker cp before the container stops. Run against a real container,
docker cp copied an empty directory: it cannot read a tmpfs mount,
which Docker documents. Pausing first, as review suggested to keep
Trilium from writing during the copy, does not change that. The
warning now says to make a backup in Trilium (Options > Backup >
Backup now), which writes one consistent file through SQLite's backup
API, and to copy the backup directory out with docker exec and tar,
then mount a volume with that backup in it as document.db. Done by
hand on a container with a tmpfs data directory, the backup came out
intact (integrity_check ok, 334 notes) and Trilium started on it with
every note and its consistency checks passing.

findOtherDocument() returned the first directory holding a document,
so one on the same mount as the new document, such as ~/trilium-data
on a volume at /home/node, hid a separate volume at the old path, and
Trilium created an empty document instead of stopping. A document on
another mount now comes first.

Both new specs failed before the change. The other scenarios were run
against an image built from this branch: the documented mount (fresh,
existing, --user 1000:1000), a named volume at /home/node,
TRILIUM_DATA_DIR=/data and a symlinked data directory start quietly;
the old path, a volume at /data, an unmounted TRILIUM_DOCUMENT_PATH
and Kubernetes without /.dockerenv stop, leaving the volume byte for
byte unchanged; no volume, an empty volume at the old path, both
documents, tmpfs and a single-file mount warn as intended.

Assisted-by: Claude Code (Claude Opus 5.5)
Comment thread apps/server/src/services/data_dir.ts Resolved
The tmpfs warning said to put the backup on a volume as document.db.
With backupEnableCompression on (or a backup password set),
Backup now writes a .tnbackup container instead of a SQLite file, and
a container started on that file, renamed, exits with "SqliteError:
file is not a database". The warning now says to mount an empty
volume and restore the file from Trilium's setup screen, which takes
.db and .tnbackup alike and asks for the password of an encrypted
one, and to unpack the tar it was copied out in first.

Checked against an image built from this branch: with compression on,
Backup now wrote backup-now.tnbackup; renamed to document.db, the
container exited with that error; restored through the setup screen
into a fresh volume, it opened all 334 notes with the consistency
checks passing.

The updated spec failed against the previous wording.

Assisted-by: Claude Code
@perfectra1n
perfectra1n merged commit 16e4f5e into main Nov 29, 2026
27 of 28 checks passed
@perfectra1n
perfectra1n deleted the fix/docker-stale-data-dir branch November 29, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant