Dockerfile 783 B

12345678910111213141516171819202122232425262728293031323334
  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 (including dev 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 only the build output from the build stage
  20. COPY --from=builder /usr/src/app/dist ./dist
  21. # Expose the application port
  22. EXPOSE 3000
  23. # Command to run the application
  24. CMD ["node", "dist/main"]