Dockerfile 881 B

123456789101112131415161718192021222324252627282930313233343536
  1. # Stage 1: Build Stage
  2. FROM node:20 AS builder
  3. # Install pnpm globally
  4. RUN corepack enable \
  5. && npm config set registry https://registry.npmmirror.com \
  6. && corepack prepare pnpm@latest --activate
  7. # Set the working directory inside the container
  8. WORKDIR /usr/src/app
  9. # Copy package.json and pnpm-lock.yaml to the working directory
  10. COPY package.json pnpm-lock.yaml ./
  11. # Install all dependencies (including dev dependencies)
  12. RUN pnpm install
  13. # Copy the rest of the application files
  14. COPY . .
  15. # Build the NestJS application
  16. RUN pnpm run build
  17. # Stage 2: Production Stage
  18. FROM node:20-alpine AS production
  19. # Set the working directory inside the container
  20. WORKDIR /usr/src/app
  21. # Copy only the build output from the build stage
  22. COPY --from=builder /usr/src/app/dist ./dist
  23. # Expose the application port
  24. EXPOSE 3000
  25. # Command to run the application
  26. CMD ["node", "dist/main"]