Chnage Dockerfile from single stage to multistage

This commit is contained in:
2026-06-09 16:09:53 +03:30
parent 3af3805863
commit 15ca17ce3b

View File

@@ -1,23 +1,23 @@
# Use the official Node.js image as the base image
FROM docker.arvancloud.ir/node:18
# ─── Stage 0: Base ────────────────────────────────────────────────────────────
FROM node:20-alpine AS base
WORKDIR /app
# Set the working directory inside the container
WORKDIR /usr/src/app
# Copy package.json and package-lock.json to the working directory
# ─── Stage 1: Dependencies ───────────────────────────────────────────────────
FROM base AS deps
COPY package*.json ./
RUN npm ci
# Install the application dependencies
RUN npm install
# Copy the rest of the application files
# ─── Stage 2: Builder ─────────────────────────────────────────────────────────
FROM deps AS builder
COPY . .
# Build the NestJS application
RUN npm run build
RUN npm ci --omit=dev --ignore-scripts
# Expose the application port
# ─── Stage 3: Production ──────────────────────────────────────────────────────
FROM base AS production
ENV NODE_ENV=production
COPY --from=builder --chown=appuser:appgroup /app/dist ./dist
COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules
COPY --from=builder --chown=appuser:appgroup /app/package.json ./package.json
EXPOSE 3000
# Command to run the application
CMD ["node", "dist/main"]
CMD ["node", "dist/main"]