|
| 1 | +FROM node:22-alpine AS base |
| 2 | + |
| 3 | +FROM base AS deps |
| 4 | +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. |
| 5 | +RUN apk add --no-cache libc6-compat |
| 6 | +WORKDIR /app |
| 7 | + |
| 8 | +# Install dependencies based on the preferred package manager |
| 9 | +COPY package.json pnpm-lock.yaml* .npmrc* ./ |
| 10 | +RUN corepack enable pnpm && pnpm i --frozen-lockfile |
| 11 | + |
| 12 | +# Rebuild the source code only when needed |
| 13 | +FROM base AS builder |
| 14 | +WORKDIR /app |
| 15 | +COPY --from=deps /app/node_modules ./node_modules |
| 16 | +COPY . . |
| 17 | + |
| 18 | +# Next.js collects completely anonymous telemetry data about general usage. |
| 19 | +# Learn more here: https://nextjs.org/telemetry |
| 20 | +# Uncomment the following line in case you want to disable telemetry during the build. |
| 21 | +# ENV NEXT_TELEMETRY_DISABLED=1 |
| 22 | +ENV SKIP_ENV_VALIDATION=true |
| 23 | + |
| 24 | +RUN corepack enable pnpm && pnpm run build |
| 25 | + |
| 26 | +# Production image, copy all the files and run next |
| 27 | +FROM base AS runner |
| 28 | +WORKDIR /app |
| 29 | + |
| 30 | +ENV NODE_ENV=production |
| 31 | +# Uncomment the following line in case you want to disable telemetry during runtime. |
| 32 | +# ENV NEXT_TELEMETRY_DISABLED=1 |
| 33 | + |
| 34 | +RUN addgroup --system --gid 1001 nodejs |
| 35 | +RUN adduser --system --uid 1001 nextjs |
| 36 | + |
| 37 | +COPY --from=builder /app/public ./public |
| 38 | + |
| 39 | +# Automatically leverage output traces to reduce image size |
| 40 | +# https://nextjs.org/docs/advanced-features/output-file-tracing |
| 41 | +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ |
| 42 | +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static |
| 43 | + |
| 44 | +USER nextjs |
| 45 | + |
| 46 | +EXPOSE 3001 |
| 47 | +ENV PORT=3001 |
| 48 | + |
| 49 | +# server.js is created by next build from the standalone output |
| 50 | +# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output |
| 51 | +ENV HOSTNAME="0.0.0.0" |
| 52 | +CMD ["node", "server.js"] |
0 commit comments