-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
47 lines (32 loc) Β· 949 Bytes
/
Dockerfile
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
43
44
45
46
47
# Use the official Node.js 20 image as the base image
FROM node:20.11.0-alpine AS base
# Create a non-root user
RUN adduser -D nonroot
# Stage 1: Build the application
FROM base AS builder
# Set working directory
WORKDIR /app
# Copy package.json and package-lock.json
COPY ./package.json ./package-lock.json ./
# Install dependencies
RUN npm install --ignore-scripts
# Copy the rest of the application code
COPY . .
# Build the application
RUN npm run build
# Switch to non-root user
USER nonroot
# Stage 2: Run the application
FROM base AS runner
# Set working directory
WORKDIR /app
# Copy package.json and package-lock.json
COPY ./package.json ./package-lock.json ./
# Install only production dependencies
RUN npm install --ignore-scripts --omit=dev
# Copy built application from the builder stage
COPY --from=builder /app/dist ./dist
# Switch to non-root user
USER nonroot
# Start the application
CMD ["npm", "run", "start:prod"]