From 82a89cd3d97d4249f75c4f9fab56191b2cfa5e78 Mon Sep 17 00:00:00 2001 From: maro Date: Fri, 18 Sep 2026 02:22:15 +0200 Subject: [PATCH] Fix media permissions inside app container --- Dockerfile | 8 ++++++-- docker/anouma-entrypoint.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 docker/anouma-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 05e7878..e923e76 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,10 @@ # .env.example) - this image builds without a database connection. FROM node:22-alpine AS base +RUN apk add --no-cache libc6-compat su-exec # ---- deps: install once, cached as its own layer ------------------------- FROM base AS deps -RUN apk add --no-cache libc6-compat WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci @@ -41,7 +41,11 @@ COPY --from=builder --chown=nextjs:nodejs /app /app # Docker volumes mounted over these paths (see docker-compose.yml). RUN mkdir -p media backups && chown -R nextjs:nodejs media backups -USER nextjs +COPY --from=builder --chown=root:root /app/docker/anouma-entrypoint.sh /usr/local/bin/anouma-entrypoint.sh +RUN chmod 755 /usr/local/bin/anouma-entrypoint.sh + +USER root +ENTRYPOINT ["/usr/local/bin/anouma-entrypoint.sh"] EXPOSE 3000 ENV PORT=3000 diff --git a/docker/anouma-entrypoint.sh b/docker/anouma-entrypoint.sh new file mode 100644 index 0000000..90de756 --- /dev/null +++ b/docker/anouma-entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -eu + +# /app/media is a persistent host bind mount in production. Its host owner +# can differ from the unprivileged application user inside the image, so fix +# the mount ownership before dropping privileges for the actual app process. +if [ -d /app/media ]; then + chown -R nextjs:nodejs /app/media + chmod 775 /app/media +fi + +exec su-exec nextjs "$@"