From 75ea9b7416a2121ee362319fc3e5b709d8f50cf7 Mon Sep 17 00:00:00 2001 From: jeanGaston Date: Thu, 30 Jul 2026 16:40:45 +0200 Subject: [PATCH] fix(docker): fix data volume ownership on fresh bind mounts /app/data is a bind mount, so the chown baked into the image is overwritten by the host directory's ownership at runtime. On a fresh prod deploy Docker creates ./data as root-owned, but the container ran as the non-root nextjs user, so Prisma couldn't open lovelope.db ("unable to open database file"). Add an entrypoint that starts as root, chowns /app/data, then drops to nextjs via su-exec before running migrations and starting the server. --- Dockerfile | 8 ++++---- docker-entrypoint.sh | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 23f1320..120eb9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,7 @@ RUN npm run build # ── Stage 3: runner ──────────────────────────────────────────────────────────── FROM node:20-alpine AS runner -RUN apk add --no-cache libc6-compat openssl +RUN apk add --no-cache libc6-compat openssl su-exec WORKDIR /app ENV NODE_ENV=production @@ -48,11 +48,11 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static RUN mkdir -p /app/data && chown nextjs:nodejs /app/data -USER nextjs +COPY --chmod=755 docker-entrypoint.sh ./docker-entrypoint.sh EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" -# Run migrations then start the server -CMD ["sh", "-c", "npx prisma migrate deploy && node server.js"] +# Fix ownership of the bind-mounted /app/data volume, then drop to nextjs +ENTRYPOINT ["./docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..4aa2fa9 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -e + +chown -R nextjs:nodejs /app/data + +exec su-exec nextjs sh -c "npx prisma migrate deploy && node server.js"