-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
35 lines (34 loc) · 1.26 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
FROM node:20.11.0 as build
# Set container working directory to /app
WORKDIR /app
# Copy npm instructions
COPY package*.json ./
# Copy npm instructions
COPY .npmrc ./
# Set npm cache to a directory the non-root user can access
RUN npm config set cache /app/.npm-cache --global
# Install dependencies with npm ci (exact versions in the lockfile), suppressing warnings
RUN npm ci --loglevel=error
# Copy app (useless stuff is ignored by .dockerignore)
COPY . .
# Build the app
RUN npm run build
# Delete all non-production dependencies to make copy in line 24 more efficient
RUN npm prune --production
# make image smaller by using multi stage build
FROM node:20.11.0-alpine
# Set the env to "production"
ENV NODE_ENV production
# Set npm cache to a directory the non-root user can access
RUN npm config set cache /app/.npm-cache --global
# get non-root user (using a number since a string could interfere with kubernetes)
USER 3301
# Set container working directory to /app
WORKDIR /app
# copy node modules and app
COPY --chown=node:node --from=build /app/node_modules /app/node_modules
COPY --chown=node:node --from=build /app/build build
# Expose the port on which the app will be running (3000 is the default that `serve` uses)
EXPOSE 3000
# start app
CMD [ "npx", "serve", "-s", "build" ]