Skip to content

Instantly share code, notes, and snippets.

@ollie314
Last active March 26, 2022 13:21
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 ollie314/9eb9fe2caf1d317243af6dea51da0a58 to your computer and use it in GitHub Desktop.
Save ollie314/9eb9fe2caf1d317243af6dea51da0a58 to your computer and use it in GitHub Desktop.
nestjs multistage non root dockerfile
# =========== Build ===========
FROM node:16.14.2-buster As development
WORKDIR /usr/src/app
RUN chown -R node:node /usr/src/app
USER node:node
COPY --chown=node:node package*.json ./
RUN npm ci
COPY --chown=node:node . .
RUN npm run build
# =========== Run ===========
# TODO: check if the alpine is not too light regarding performance
FROM node:16-alpine As production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src/app
RUN chown -R node:node /usr/src/app
USER node:node
COPY --chown=node:node package*.json ./
RUN npm ci --only=production
COPY --chown=node:node --from=development /usr/src/app/dist ./dist
EXPOSE 3000
CMD ["node", "dist/main"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment