Dockerfile 868 B

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