11# Stage 1: Build the production assets
2- FROM node:22-alpine AS builder
2+ FROM node:22 AS builder
33
44WORKDIR /app
55
@@ -10,27 +10,25 @@ RUN npm install
1010# Copy the rest of your application code
1111COPY . .
1212
13- # Build the production assets; this creates the .next directory
13+ # Build the production assets (standalone output)
1414RUN npm run build
1515
1616# Stage 2: Run the production app
17- FROM node:22-alpine AS runner
17+ FROM node:22-slim AS runner
1818
1919WORKDIR /app
2020
21- # Copy only the necessary files from the builder stage
22- COPY --from=builder /app/package*.json ./
23- COPY --from=builder /app/.next ./.next
24- COPY --from=builder /app/public ./public
21+ ENV NODE_ENV=production
2522
26- # (Optional) Copy any other files you need in production
27- # COPY --from=builder /app/src ./src
23+ # Copy the standalone server (includes all needed node_modules)
24+ COPY --from=builder /app/.next/standalone ./
2825
29- # Install only production dependencies
30- RUN npm ci --production
26+ # Copy static assets and public files (not included in standalone)
27+ COPY --from=builder /app/.next/static ./.next/static
28+ COPY --from=builder /app/public ./public
3129
3230# Expose the port your app listens on
3331EXPOSE 3000
3432
35- # Start the production server
36- CMD ["npm " , "run" , "start " ]
33+ # Start the standalone server
34+ CMD ["node " , "server.js " ]
0 commit comments