forked from monstar-lab-oss/nestjs-starter-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.prod
42 lines (30 loc) · 934 Bytes
/
Dockerfile.prod
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
35
36
37
38
39
40
41
42
# Stage 1: Build the application
FROM node:20.14.0-bookworm-slim as builder
WORKDIR /usr/src/app
# Install dependencies
COPY package.json package-lock.json ./
RUN npm ci
# Copy the rest of the application files
COPY . .
# Build the application
ARG APP_ENV=production
ENV NODE_ENV=${APP_ENV}
RUN npm run build
# Prune development dependencies
RUN npm prune --production
# Stage 2: Create the production image
FROM node:20.14.0-bookworm-slim
WORKDIR /usr/src/app
# Copy only the necessary files from the builder stage
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/package*.json ./
COPY --from=builder /usr/src/app/dist ./dist
# Set the environment variables
ARG APP_ENV=production
ENV NODE_ENV=${APP_ENV}
# Expose the application port
EXPOSE 3000
# Use a non-root user for security
USER node
# Set the default command to run the application
CMD [ "npm", "run", "start:prod" ]