date
Oct 2, 2025
slug
dockerfile
status
Published
tags
NodeJs
summary
Setting dockerFile
type
Post
# STAGE 1: Builder
# Use a specific Node.js version for reproducibility.
FROM node:22.11.0-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Remove devDependencies to reduce the size of node_modules.
RUN npm prune --production
# STAGE 2: Runner
FROM node:22.11.0-alpine AS runner
ENV NODE_ENV=production
ENV APP_USER=nestjs
# Create a non-root user and group for security.
RUN adduser --system ${APP_USER}
WORKDIR /home/${APP_USER}/app
COPY --from=builder /app/package*.json ./
RUN npm ci --production
COPY --from=builder --chown=${APP_USER}:${APP_USER} /app/dist ./dist
USER ${APP_USER}
EXPOSE 8000
CMD ["node", "dist/main.js"]