38 lines
871 B
Docker
38 lines
871 B
Docker
# Stage 1: Build Stage
|
|
FROM node:20 AS builder
|
|
|
|
# Install pnpm globally
|
|
RUN npm install -g pnpm@latest
|
|
|
|
# Set the working directory inside the container
|
|
WORKDIR /usr/src/app
|
|
|
|
# Copy package.json and pnpm-lock.yaml to the working directory
|
|
COPY package.json pnpm-lock.yaml ./
|
|
|
|
# Install all dependencies
|
|
RUN pnpm install
|
|
|
|
# Copy the rest of the application files
|
|
COPY . .
|
|
|
|
# Build the NestJS application
|
|
RUN pnpm run build
|
|
|
|
# Stage 2: Production Stage
|
|
FROM node:20-alpine AS production
|
|
|
|
# Set the working directory inside the container
|
|
WORKDIR /usr/src/app
|
|
|
|
# Copy necessary files from the build stage
|
|
COPY --from=builder /usr/src/app/dist ./dist
|
|
COPY --from=builder /usr/src/app/node_modules ./node_modules
|
|
COPY --from=builder /usr/src/app/package.json ./package.json
|
|
|
|
# Expose the application port
|
|
EXPOSE 3000
|
|
|
|
# Command to run the application
|
|
CMD ["node", "dist/main"]
|