FROM node:18-alpine AS base WORKDIR /app # Install app dependencies with caching for package.json changes COPY package.json package-lock.json ./ RUN npm ci # Copy the rest of the application code COPY . . # Build the application (if applicable, e.g., React, Vue) RUN npm run build # --- Final Production Image --- FROM node:18-alpine WORKDIR /app # Copy only the built artifacts and production dependencies from 'base' stage COPY --from=base /app/node_modules ./node_modules COPY --from=base /app/build ./build COPY --from=base /app/package.json ./ ENV NODE_ENV=production EXPOSE 3000 CMD ["node", "build/index.js"]