# Build stage FROM node:20-alpine AS builder WORKDIR /app # Copy package files COPY package*.json ./ # Install dependencies RUN npm ci # Copy source COPY . . # Build the app RUN npm run build # Production stage FROM node:20-alpine WORKDIR /app # Copy package files COPY package*.json ./ # Install production dependencies only RUN npm ci --omit=dev # Copy built app from builder COPY --from=builder /app/.next ./.next # Copy public folder if it exists in the builder # Using sh to handle the conditional copy RUN mkdir -p ./public # Create non-root user RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001 # Set permissions RUN chown -R nextjs:nodejs /app USER nextjs # Start the app CMD ["npm", "run", "start"] EXPOSE 3000