-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
39 lines (27 loc) · 925 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
# Use a multi-stage build to keep the final image lean
# Stage 1: Build the application
FROM node:20-alpine as builder
# Set the working directory in the container
WORKDIR /usr/src/app
# Copy package.json and package-lock.json (or yarn.lock if you use Yarn)
COPY package*.json ./
# Install all dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
# Build the application
RUN npm run build
# Stage 2: Create the lean production image
FROM node:20-alpine
# Set the working directory in the container
WORKDIR /usr/src/app
# Copy package.json and package-lock.json (or yarn.lock if you use Yarn)
COPY package*.json ./
# Install only production dependencies
RUN npm install --only=production
# Copy built assets from the builder stage
COPY --from=builder /usr/src/app/dist ./dist
# Your application's default port
EXPOSE 3000
# Command to run the application
CMD ["node", "dist/src/index.js"]