Dockerfile 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Stage 1: Build Stage
  2. FROM node:22 AS builder
  3. # Set npm registry to Tencent Cloud and install pnpm globally
  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:22 AS production
  18. # Set npm registry to Tencent Cloud and install pnpm globally
  19. RUN npm config set registry https://mirrors.cloud.tencent.com/npm/ \
  20. && npm install -g pnpm@latest
  21. # Set the working directory inside the container
  22. WORKDIR /usr/src/app
  23. # Copy the build output and production dependencies from the build stage
  24. COPY --from=builder /usr/src/app/dist ./dist
  25. COPY --from=builder /usr/src/app/package.json /usr/src/app/pnpm-lock.yaml ./
  26. # Install only production dependencies
  27. RUN pnpm install --prod
  28. # Expose the application port
  29. EXPOSE 3000
  30. # Command to run the application
  31. CMD ["node", "dist/main"]