-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
51 lines (37 loc) · 1.48 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
FROM node:alpine
# Set necessary environment variables.
ENV NODE_ENV=production \
NPM_CONFIG_PREFIX=/home/node/.npm-global \
PATH=$PATH:/home/node/.npm-global/bin:/home/node/node_modules/.bin:$PATH
# For handling Kernel signals properly
RUN apk add --no-cache tini
# Create the working directory, including the node_modules folder for the sake of assigning ownership in the next command
RUN mkdir -p /usr/src/app/node_modules
# Change ownership of the working directory to the node:node user:group
# This ensures that npm install can be executed successfully with the correct permissions
RUN chown -R node:node /usr/src/app
# Set the user to use when running this image
# Non previlage mode for better security (this user comes with official NodeJS image).
USER node
# Set the default working directory for the app
# It is a best practice to use the /usr/src/app directory
WORKDIR /usr/src/app
# Copy package.json, package-lock.json
# Copying this separately prevents re-running npm install on every code change.
COPY --chown=node:node package.json ./
COPY --chown=node:node yarn-lock.json ./
# Install dependencies.
# RUN npm i -g @nestjs/cli
RUN yarn
# Necessary to run before adding application code to leverage Docker cache
RUN npm cache clean --force
# RUN mv node_modules ../
# Bundle app source
COPY --chown=node:node . ./
# Display directory structure
RUN ls -l
# Expose API port
EXPOSE 3000
ENTRYPOINT ["/sbin/tini", "--"]
# Run the web service on container startup
CMD [ "npm", "start" ]