-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
34 lines (27 loc) · 909 Bytes
/
Dockerfile
File metadata and controls
34 lines (27 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Multi-stage Dockerfile for NestJS app
FROM node:20-alpine AS base
WORKDIR /app
# Install dependencies separately for layer caching
FROM base AS deps
COPY package.json package-lock.json ./
RUN npm ci --no-audit --no-fund
# Build the application (needs devDependencies like @nestjs/cli)
FROM deps AS build
COPY . .
RUN npm run build
# Prune dev dependencies to shrink runtime size
RUN npm prune --omit=dev
# Final runtime image
FROM node:20-alpine AS runner
ENV NODE_ENV=production
ENV PORT=3001
WORKDIR /app
# Only copy what is needed at runtime
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package.json ./package.json
COPY --from=build /app/package-lock.json ./package-lock.json
COPY --from=build /app/dist ./dist
COPY --from=build /app/public ./public
EXPOSE 3001
# Because tsconfig includes project root, compiled entry is dist/src/main.js
CMD ["node", "dist/main.js"]