-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
45 lines (30 loc) · 1.21 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
FROM node:20-alpine3.19 AS builder
WORKDIR /build
# install dependencies
# copy only package.json files for better caching
# (if no dependencies are changed, there is no need to reinstall them, so it is faster to use the cache)
COPY package*.json ./
RUN npm ci --fund=false
# copy rest of src files etc.
COPY . .
# build and install only production dependencies
RUN npm run build
# install only production dependencies for reducing image size and security (no need for dev dependencies in prod env)
RUN npm ci --omit=dev --audit=false --fund=false
######################################################################
FROM node:20-alpine3.19
WORKDIR /app
LABEL org.opencontainers.image.authors="Nico W. <[email protected]>"
EXPOSE 8080
# set node env to production because it will not be set as default anywhere
ENV NODE_ENV=production
HEALTHCHECK --interval=10s --retries=2 CMD npx docker-healthcheck || exit 1
# copy files from build stage
COPY --from=builder /build/dist/ dist/
COPY --from=builder /build/package*.json ./
COPY --from=builder /build/node_modules/ node_modules/
# [IF WANTED] change user permissions
#RUN chown node:node -R *
# [IF WANTED] switch to node user for more security
#USER node
ENTRYPOINT ["node", "."]