29e6933505
Build and Push / build (push) Successful in 54s
Bind mounts override the image's chown, so the container's nextjs user (uid 1001) couldn't write to /app/data when it was mounted from a host dir owned by someone else. Start as root, fix ownership in an entrypoint, then drop to nextjs via su-exec. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
46 lines
1.3 KiB
Docker
46 lines
1.3 KiB
Docker
# syntax=docker/dockerfile:1.7
|
|
ARG NODE_VERSION=22-alpine
|
|
|
|
# ── deps: install node_modules (with native build tools for better-sqlite3) ──
|
|
FROM node:${NODE_VERSION} AS deps
|
|
RUN apk add --no-cache libc6-compat python3 make g++
|
|
WORKDIR /app
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci
|
|
|
|
# ── builder: produce the standalone Next.js bundle ──
|
|
FROM node:${NODE_VERSION} AS builder
|
|
WORKDIR /app
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
RUN npm run build
|
|
|
|
# ── runner: minimal runtime image ──
|
|
FROM node:${NODE_VERSION} AS runner
|
|
WORKDIR /app
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
ENV PORT=3000
|
|
ENV HOSTNAME=0.0.0.0
|
|
|
|
RUN apk add --no-cache su-exec \
|
|
&& addgroup --system --gid 1001 nodejs \
|
|
&& adduser --system --uid 1001 nextjs
|
|
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
RUN mkdir -p /app/data && chown nextjs:nodejs /app/data
|
|
|
|
COPY docker-entrypoint.sh /usr/local/bin/
|
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
|
|
# Stay as root so the entrypoint can fix bind-mount ownership, then drop
|
|
# privileges via su-exec before launching the server.
|
|
EXPOSE 3000
|
|
VOLUME ["/app/data"]
|
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
|
CMD ["node", "server.js"]
|