Skip to content

Instantly share code, notes, and snippets.

@vnnvanhuong
Last active August 23, 2020 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vnnvanhuong/4c6d0a43f9b40e75a5f56d4107ac109a to your computer and use it in GitHub Desktop.
Save vnnvanhuong/4c6d0a43f9b40e75a5f56d4107ac109a to your computer and use it in GitHub Desktop.
FROM node:12
LABEL author="Huong Nguyen (vnnvanhuong@gmail.com)"
# Use NODE_ENV=production to ensure that
# logging is kept to a minimum
# more caching levels takes
# don’t install dev node_modules
ARG NODE_ENV=production
ARG UID=999
ARG GUI=999
ENV NODE_ENV=${NODE_ENV}
# Use pre-existing "/usr/src/app" rather than create a new dir such as "mkdir /app"
WORKDIR /usr/src/app
# change the uid/gid
RUN groupmod -g ${UID} node && usermod -u ${UID} -g ${GUI} node
# give another name "gnouh" for user "node"
RUN usermod -d /home/gnouh -l gnouh node
# Copy package*.json before copying the source code
# Docker will cache node_modules as a separated layer
# Hence, node_modules is not need to installed again if no change in package.json
COPY package*.json ./
RUN npm ci
COPY . .
EXPOSE 8080
# bypass the package.json's start command
CMD [ "node", "server.js" ]
USER gnouh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment