48 lines · 1.0 KB · Dockerfile
RawDownload
FROM node:20-alpine AS base # Install dependencies only when neededFROM base AS depsWORKDIR /app COPY package.json package-lock.json* ./RUN npm ci # Rebuild the source code only when neededFROM base AS builderWORKDIR /appCOPY --from=deps /app/node_modules ./node_modulesCOPY . . # Build arguments for environment variablesARG NEXT_PUBLIC_API_URLENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} RUN npm run build # Production image, copy all the files and run nextFROM base AS runnerWORKDIR /app ENV NODE_ENV=production RUN addgroup --system --gid 1001 nodejsRUN adduser --system --uid 1001 nextjs COPY --from=builder /app/public ./public # Set the correct permission for prerender cacheRUN mkdir .nextRUN chown nextjs:nodejs .next # Automatically leverage output traces to reduce image sizeCOPY --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=3000ENV HOSTNAME="0.0.0.0" CMD ["node", "server.js"]