Files
lead-scraper/Dockerfile
Timo Uttenweiler 807b82f633 Fix Docker volume permissions for /data (SQLite)
Add su-exec to runner stage, run entrypoint as root to chown /data,
then drop to nextjs user for migrations and app start. Fixes permission
denied errors when Docker volume is mounted as root.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-09 11:19:27 +02:00

73 lines
2.8 KiB
Docker

# ──────────────────────────────────────────────
# Stage 1: Install dependencies
# ──────────────────────────────────────────────
FROM node:22-alpine AS deps
WORKDIR /app
# Install native build tools needed for better-sqlite3
RUN apk add --no-cache python3 make g++
COPY package.json package-lock.json ./
RUN npm ci
# ──────────────────────────────────────────────
# Stage 2: Build the application
# ──────────────────────────────────────────────
FROM node:22-alpine AS builder
WORKDIR /app
RUN apk add --no-cache python3 make g++
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Generate Prisma client
RUN npx prisma generate
# Build Next.js (output: standalone)
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build
# ──────────────────────────────────────────────
# Stage 3: Production runtime
# ──────────────────────────────────────────────
FROM node:22-alpine AS runner
WORKDIR /app
RUN apk add --no-cache python3 make g++ su-exec
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
# Non-root user for security
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
# Copy standalone output
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
# Copy Prisma files (schema + migrations + generated client)
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
COPY --from=builder /app/node_modules/better-sqlite3 ./node_modules/better-sqlite3
COPY --from=builder /app/node_modules/@prisma/adapter-better-sqlite3 ./node_modules/@prisma/adapter-better-sqlite3
COPY --from=builder /app/node_modules/@prisma/driver-adapter-utils ./node_modules/@prisma/driver-adapter-utils
COPY --from=builder /app/node_modules/prisma ./node_modules/prisma
# Entrypoint script that runs migrations then starts the app
COPY docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
# Data directory for SQLite — must be a volume
RUN mkdir -p /data && chown nextjs:nodejs /data
# Entrypoint runs as root, fixes /data permissions, then drops to nextjs via su-exec
EXPOSE 3000
ENTRYPOINT ["./docker-entrypoint.sh"]