Dockerfile 1002 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 the build output and dependencies from the build stage
  21. COPY --from=builder /usr/src/app/dist ./dist
  22. COPY --from=builder /usr/src/app/node_modules ./node_modules
  23. COPY --from=builder /usr/src/app/package.json ./package.json
  24. # Expose the application port
  25. EXPOSE 3000
  26. # Command to run the application
  27. CMD ["node", "dist/main"]