11# Dockerfile (multi-stage) - optimized for Next.js w/ Prisma
22# Build stage
3- FROM node:22-alpine AS builder
3+ FROM node:22-slim AS builder
44WORKDIR /app
55
6+ # Install system dependencies for Prisma
7+ RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*
8+
69# Install pnpm and build deps
710RUN corepack enable pnpm
811COPY package.json pnpm-lock.yaml ./
@@ -11,24 +14,29 @@ RUN pnpm install --frozen-lockfile
1114# Copy sources
1215COPY . .
1316
14- # Generate prisma client & build
17+ # Generate prisma client with correct engine for Alpine
1518RUN pnpm exec prisma generate
1619RUN pnpm run build
1720
1821# Production image
19- FROM node:22-alpine AS runner
22+ FROM node:22-slim AS runner
2023WORKDIR /app
2124ENV NODE_ENV=production
2225
26+ # Install runtime dependencies for Prisma
27+ RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*
28+
2329# Create a non-root user
24- RUN addgroup -S appgroup && adduser -S appuser -G appgroup
30+ RUN groupadd --system --gid 1001 appgroup \
31+ && useradd --system --uid 1001 --gid appgroup --shell /bin/bash --create-home appuser
2532
2633# Copy built artifacts + node_modules (only prod)
2734COPY --from=builder /app/.next ./.next
2835COPY --from=builder /app/public ./public
2936COPY --from=builder /app/node_modules ./node_modules
3037COPY --from=builder /app/package.json ./package.json
3138COPY --from=builder /app/prisma ./prisma
39+ COPY --from=builder /app/src/generated ./src/generated
3240
3341# Copy entrypoint script
3442COPY ./docker/entrypoint.sh /entrypoint.sh
0 commit comments