Dockerfile 871 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # Stage 1: Build Stage
  2. FROM node:20 AS builder
  3. # Install pnpm globally
  4. RUN npm install -g pnpm@latest
  5. # Set the working directory inside the container
  6. WORKDIR /usr/src/app
  7. # Copy package.json and pnpm-lock.yaml to the working directory
  8. COPY package.json pnpm-lock.yaml ./
  9. # Install all dependencies
  10. RUN pnpm install
  11. # Copy the rest of the application files
  12. COPY . .
  13. # Build the NestJS application
  14. RUN pnpm run build
  15. # Stage 2: Production Stage
  16. FROM node:20-alpine AS production
  17. # Set the working directory inside the container
  18. WORKDIR /usr/src/app
  19. # Copy necessary files from the build stage
  20. COPY --from=builder /usr/src/app/dist ./dist
  21. COPY --from=builder /usr/src/app/node_modules ./node_modules
  22. COPY --from=builder /usr/src/app/package.json ./package.json
  23. # Expose the application port
  24. EXPOSE 3000
  25. # Command to run the application
  26. CMD ["node", "dist/main"]