# Stage 1: Build React app FROM node:20 AS builder WORKDIR /app COPY package*.json ./ # RUN npm install --legacy-peer-deps RUN npm ci --legacy-peer-deps COPY . . RUN npm run build # Stage 2: Serve React app using Nginx FROM nginx:alpine COPY --from=builder /app/build /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] # # =============================== # # Stage 1: Build React App # # =============================== # FROM node:20-alpine AS builder # # Ensure smaller final node image # ENV NODE_ENV=production # WORKDIR /app # # Install dependencies using clean cache # COPY package*.json ./ # RUN npm ci --legacy-peer-deps # # Copy only required app files # COPY . . # # Build optimized production bundle # RUN npm run build # # =============================== # # Stage 2: Nginx to serve React # # =============================== # FROM nginx:1.27-alpine # # Remove default nginx static files # RUN rm -rf /usr/share/nginx/html/* # # Copy build output # COPY --from=builder /app/build /usr/share/nginx/html # # Use optimized Nginx config (gzip, caching, SPA routing) # COPY nginx.conf /etc/nginx/conf.d/default.conf # EXPOSE 80 # CMD ["nginx", "-g", "daemon off;"]