-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
38 lines (26 loc) · 714 Bytes
/
Dockerfile
File metadata and controls
38 lines (26 loc) · 714 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
35
36
37
38
# Stage 1: Build
FROM node:18-alpine AS builder
WORKDIR /app
# Copy package files first (caching optimization)
COPY package*.json ./
# Install dependencies (including devDependencies for build)
RUN npm install
# Copy source code
COPY . .
# ---
# Stage 2: Production
FROM node:18-alpine
WORKDIR /app
# Copy only production dependencies
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/src ./src
# Install PM2 globally (process manager)
RUN npm install -g pm2
# Environment variables
ENV NODE_ENV=production
ENV PORT=5000
# Expose port
EXPOSE 5000
# Run with PM2 (cluster mode)
CMD ["pm2-runtime", "start", "src/app.js", "-i", "max"]