generated from UK-Export-Finance/nestjs-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
51 lines (37 loc) · 1.18 KB
/
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
48
49
50
51
###################
# 1. BUILD
###################
FROM node:21.4.0-alpine3.17 AS build
# Alpine Linux install packages
RUN apk add bash curl
RUN rm -rf /var/cache/apk/*
WORKDIR /app
# NPM
COPY --chown=node:node package.json .
COPY --chown=node:node package-lock.json .
RUN npm ci --legacy-peer-deps
COPY --chown=node:node src src
COPY --chown=node:node nest-cli.json .
COPY --chown=node:node tsconfig.json .
COPY --chown=node:node tsconfig.build.json .
# Build with all dependencies
RUN npm run build
# Lean NPM - Only install `dependencies`
# `devDependencies` will still be resolved inside `package-lock.json`,
# however they will not be installed inside `node_modules` directory.
RUN npm ci --legacy-peer-deps --omit=dev
# Non-root user
USER node
###################
# 2. PRODUCTION
###################
FROM node:21.4.0-alpine3.17 AS production
WORKDIR /app
# Copy from `build` to `prod`
COPY --chown=node:node --from=build /app/package.json .
COPY --chown=node:node --from=build /app/package-lock.json .
COPY --chown=node:node --from=build /app/node_modules ./node_modules
COPY --chown=node:node --from=build /app/dist ./dist
# Non-root user
USER node
CMD ["npm", "run", "start:prod"]