Skip to content

Instantly share code, notes, and snippets.

@correaswebert
Created January 26, 2021 18:16
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 correaswebert/f67f453a059aa6ea21c1dba8bab2fb59 to your computer and use it in GitHub Desktop.
Save correaswebert/f67f453a059aa6ea21c1dba8bab2fb59 to your computer and use it in GitHub Desktop.
A simple Dockerfile.
# ensure the exact baseimage is used (exemplified below)
FROM node:lts-alpine@sha256:b2da3316acdc2bec442190a1fe10dc094e7ba4121d029cb32075ff59bb27390a
# install dumb-init for invoking docker
RUN apk add dumb-init
# optimize for production
ENV NODE_ENV production
WORKDIR /usr/src/app
# 'node' process owns the files now, not 'root'
COPY --chown=node:node . .
# do not install dev dependencies
RUN yarn install --production=true
# make 'node' as the process owner, not 'root'
USER node
# prevent starting process as PID1 by using dumb-init
CMD ["dumb-init", "node", "server.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment