Skip to content

Instantly share code, notes, and snippets.

@simonme
Last active May 2, 2020 13:24
Show Gist options
  • Save simonme/a6da0b4ea10e52454ee9f1b5f13a188d to your computer and use it in GitHub Desktop.
Save simonme/a6da0b4ea10e52454ee9f1b5f13a188d to your computer and use it in GitHub Desktop.
Node.js Best Practices Dockerfile (with build step). See this article for more info: https://menssen.tech/nodejs-docker-best-practices
### build stage
FROM node:12.16.1-alpine3.11 AS build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
### cmd stage
FROM node:12.16.1-alpine3.11
WORKDIR /usr/src/app
RUN chown node:node /usr/src/app
RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]
USER node
COPY package*.json ./
RUN NODE_ENV=production npm install
COPY --from=build /usr/src/app/dist ./dist
EXPOSE 8080
CMD [ "node", "dist/index.js" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment