- Changed FROM node:20-alpine to node:20-slim for both builder and runner stages - Alpine (musl) is incompatible with Next.js SWC binary (glibc) - Debian slim provides 80% smaller image compared to full node:20 (~180MB vs ~900MB) - Fully compatible with Next.js and SWC without any patches - Better performance and stability on Synology NAS
41 lines
757 B
Docker
41 lines
757 B
Docker
# Build stage
|
|
FROM node:20-slim AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Dependencies
|
|
COPY package.json package-lock.json* ./
|
|
RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
|
|
|
|
# Source code
|
|
COPY . .
|
|
|
|
# Build
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
RUN npm run build
|
|
|
|
# Production stage
|
|
FROM node:20-slim AS runner
|
|
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
# Copy standalone build
|
|
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
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
CMD ["node", "server.js"]
|