# Use the official Node.js image from Docker Hub FROM node:18 AS build # Set the working directory WORKDIR /usr/src/app # Copy package.json and package-lock.json for installing dependencies COPY package.json package-lock.json ./ # Install dependencies RUN npm install # Copy the entire project COPY . . # Build the project RUN npm run build # Use a smaller image for the production environment FROM node:18-alpine # Set environment to production ENV NODE_ENV production # Set the working directory WORKDIR /usr/src/app # Copy from the "build" stage COPY --from=build /usr/src/app/.next ./.next COPY --from=build /usr/src/app/package.json ./package.json COPY --from=build /usr/src/app/package-lock.json ./package-lock.json # Install only production dependencies RUN npm install --production EXPOSE 3000 ENV PORT 3000 # Command to run the application CMD ["npm", "start"]