# Stage 1: Build the Next.js application FROM node:20-alpine AS builder RUN apk add --no-cache libc6-compat WORKDIR /app # Install dependencies COPY frontend/package.json frontend/package-lock.json ./ RUN npm install # Copy source files and build the Next.js application COPY frontend ./ RUN npm run build # Install PM2 globally RUN npm install -g pm2 # Stage 2: Serve the Next.js application using PM2 and Nginx FROM bitnami/nginx:1.26.1 # Copy custom Nginx configuration COPY nginx.conf /opt/bitnami/nginx/conf/nginx.conf # Copy the Next.js build from the builder stage COPY --from=builder /app /app WORKDIR /app # Expose the necessary port EXPOSE 7860 # Start Next.js with PM2 CMD ["pm2-runtime", "start", "npm", "--", "start"]