# Production-ready Dockerfile for Next.js FROM node:20-alpine AS base WORKDIR /app ENV NODE_ENV=production # Install dependencies only, then copy source for better caching COPY package.json package-lock.json* ./ RUN npm ci --omit=dev # Copy all files and build the Next.js app COPY . . RUN npm run build # Use a non-root user for security RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001 USER nextjs EXPOSE 3000 CMD ["npm", "start"]