From 24a2d275a0578a2e8f632592e95fe2d5b6b945a3 Mon Sep 17 00:00:00 2001 From: tajniak81 <13187254+tajniak81@users.noreply.github.com> Date: Fri, 13 Nov 2026 18:35:08 +0100 Subject: [PATCH] Fix docwell-server data dir ownership on start The server runs as docwell (uid 10001), but a host bind mount for SERVER_DATA, or a volume created by an older image, arrives owned by root, so the search index failed with "mkdir /data/search.bleve: permission denied". The image now starts as root through a small entrypoint that chowns DOCWELL_DATA_DIR to docwell when needed, then runs docwell-server as docwell via su-exec. A container already started with a non-root user: skips the fix and runs the server directly. Co-Authored-By: Claude Opus 5.5 --- Server/Dockerfile | 8 +++++--- Server/entrypoint.sh | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 Server/entrypoint.sh diff --git a/Server/Dockerfile b/Server/Dockerfile index 661f60d..3b0a319 100644 --- a/Server/Dockerfile +++ b/Server/Dockerfile @@ -31,13 +31,15 @@ RUN CGO_ENABLED=0 GOWORK=off GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpat -o /out/docwell-server ./cmd/docwell-server FROM alpine:3.22 -RUN apk add --no-cache ca-certificates && adduser -D -u 10001 docwell && mkdir /data && chown docwell /data +RUN apk add --no-cache ca-certificates su-exec && adduser -D -u 10001 docwell && mkdir /data && chown docwell /data COPY --from=build /out/docwell-server /usr/local/bin/docwell-server -USER docwell +# Starts as root, fixes the ownership of /data (a bind mount arrives owned by +# root), then runs the server as docwell. See entrypoint.sh. +COPY --chmod=0755 Server/entrypoint.sh /usr/local/bin/docwell-entrypoint # The search index; it is rebuilt from PocketBase when missing. ENV DOCWELL_DATA_DIR=/data VOLUME /data EXPOSE 8080 HEALTHCHECK --interval=10s --timeout=3s --retries=5 \ CMD wget -qO- http://127.0.0.1:8080/healthz >/dev/null || exit 1 -ENTRYPOINT ["docwell-server"] +ENTRYPOINT ["docwell-entrypoint"] diff --git a/Server/entrypoint.sh b/Server/entrypoint.sh new file mode 100644 index 0000000..8d01d83 --- /dev/null +++ b/Server/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# docwell-server entrypoint. Started as root only to make the data directory +# writable for the docwell user: a host bind mount, or a volume created by an +# older image, arrives owned by root, and the search index could not be +# written. Then it drops to docwell for good. +set -eu + +DATA_DIR="${DOCWELL_DATA_DIR:-/data}" + +if [ "$(id -u)" = "0" ]; then + mkdir -p "$DATA_DIR" + if [ "$(stat -c %u "$DATA_DIR")" != "10001" ]; then + echo "Fixing $DATA_DIR ownership for docwell (uid=10001)" + chown -R docwell:docwell "$DATA_DIR" + fi + exec su-exec docwell docwell-server "$@" +fi + +# Already unprivileged (e.g. `user:` set in compose): run as is. +exec docwell-server "$@"