Skip to content

Instantly share code, notes, and snippets.

@morintd
Last active August 18, 2023 16:36
Show Gist options
  • Save morintd/f3a6bb08228bf30d705888b57e8dd1d4 to your computer and use it in GitHub Desktop.
Save morintd/f3a6bb08228bf30d705888b57e8dd1d4 to your computer and use it in GitHub Desktop.
# Use a fixed Long-Term-Support (LTS) version of node, with the alpine distribution
FROM node:18.17.0-alpine
# Necessary dependencies
RUN apk update && apk add --no-cache tini
# Replace by next line if you need to install & build native dependencies
# RUN apk add --no-cache tini g++ make py3-pip
# 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 privilege 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 /usr/src/app
COPY --chown=node:node yarn.lock /usr/src/app
# Install dependencies
RUN yarn
# Bundle app source
COPY --chown=node:node . ./
# Init with tini
ENTRYPOINT ["/sbin/tini", "--"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment