fix(docker): make /app/data writable by node user on bind-mounted volumes
The container ran as the unprivileged "node" user, but bind-mounted host
directories (e.g. ./data:/app/data in docker-compose or an Unraid appdata
folder) are mounted with root ownership. The node user therefore could not
create trxtd.db in /app/data, failing at startup with:
Error: unable to open database file
at file:///app/server/db.mjs:12
Fix:
- Add docker-entrypoint.sh that mkdir/chown /app/data to node:node on
container start, then drops privileges back to node via su-exec
- Install su-exec in the runtime stage (apk add --no-cache su-exec)
- Remove USER node so the entrypoint runs as root and can fix ownership,
with privilege dropping handled inside the entrypoint instead
- Wire the script up as ENTRYPOINT, keeping CMD as the app itself
The mount path itself is unchanged (/app/data, host ./data). Verified with
a real bind mount: /health responds ok and trxtd.db/-shm/-wal are created
in the mounted directory.
This commit is contained in:
parent
1a9ac5bf45
commit
1abc08b60f
2 changed files with 22 additions and 8 deletions
11
docker-entrypoint.sh
Normal file
11
docker-entrypoint.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Ensure the data directory exists and is owned by the node user.
|
||||
# This fixes permission issues with bind-mounted volumes (e.g. ./data:/app/data)
|
||||
# where the host directory is owned by root but the container runs as node.
|
||||
mkdir -p /app/data
|
||||
chown -R node:node /app/data 2>/dev/null || true
|
||||
|
||||
# Drop privileges and run the actual application as node
|
||||
exec su-exec node "$@"
|
||||
Loading…
Add table
Add a link
Reference in a new issue