-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
34 lines (27 loc) · 818 Bytes
/
Dockerfile
File metadata and controls
34 lines (27 loc) · 818 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
FROM node:20-alpine AS build
WORKDIR /app
# Install dependencies
COPY package*.json ./
COPY tsconfig.json ./
COPY typeorm.config.js ./
RUN npm install -g @nestjs/cli
RUN npm install
# Build the app
COPY src/ ./src/
RUN npm run build
RUN npm prune --production
# Second stage
FROM node:20-alpine
# Create app directory and user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
RUN mkdir /app && chown appuser:appgroup /app
USER appuser
WORKDIR /app
# Copy config files needed for migrations
COPY --chown=appuser:appgroup package*.json ./
COPY --chown=appuser:appgroup typeorm.config.js ./
# Copy built assets from build stage
COPY --from=build --chown=appuser:appgroup /app/dist ./dist
COPY --from=build --chown=appuser:appgroup /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/main.js"]