-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (31 loc) · 1.01 KB
/
Dockerfile
File metadata and controls
47 lines (31 loc) · 1.01 KB
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
# Based on best pratices provided by Snyk.io
# https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/
# base node image
FROM node:21-bullseye-slim as base
# set for base and all layer that inherit from it
# ENV NODE_ENV production
# Install all noe_modules, including dev dependencies
FROM base as deps
WORKDIR /myapp
ADD package.json package-lock.json ./
RUN npm install
# Build the app
FROM base as build
WORKDIR /myapp
COPY --from=deps /myapp/node_modules /myapp/node_modules
ADD . .
RUN npm run build
# Setup production node_modules
FROM base as production-deps
WORKDIR /myapp
COPY --from=deps /myapp/node_modules /myapp/node_modules
ADD package.json package-lock.json ./
RUN npm install --production
# Finally, build the production image with minimal footprint
FROM base
WORKDIR /myapp
COPY --from=production-deps /myapp/node_modules /myapp/node_modules
COPY --from=build /myapp/emails /myapp/emails
COPY --from=build /myapp/dist /myapp/dist
ADD . .
CMD ["node", "dist/index.js"]