Skip to content

Build your personal knowledge base with Trilium Notes

fix(docker): start Trilium directly when the container is not root

Elian Doran23c48bdef7a2
diff --git a/apps/server/start-docker.sh b/apps/server/start-docker.sh
index 8d38923c1c..6fe9d2a31d 100644
--- a/apps/server/start-docker.sh
+++ b/apps/server/start-docker.sh
@@ -1,7 +1,16 @@
#!/bin/sh
+# Without root (`--user`, Kubernetes `runAsNonRoot`, rootless Podman) the container can neither
+# remap `node` nor change ownership, so Trilium runs as the user it was started with.
+if [ "$(id -u)" != "0" ]; then
+ if [ -n "${USER_UID}${USER_GID}" ]; then
+ echo "Running as $(id -u):$(id -g), so USER_UID and USER_GID are ignored; set the user with --user instead"
+ fi
+ exec node ./main.mjs
+fi
+
[ ! -z "${USER_UID}" ] && usermod -u ${USER_UID} node || echo "No USER_UID specified, leaving 1000"
[ ! -z "${USER_GID}" ] && groupmod -og ${USER_GID} node || echo "No USER_GID specified, leaving 1000"
chown -R node:node /home/node
-exec su -c "node ./main.mjs" node
\ No newline at end of file
+exec su -c "node ./main.mjs" node