Last active
March 26, 2022 13:21
-
-
Save ollie314/9eb9fe2caf1d317243af6dea51da0a58 to your computer and use it in GitHub Desktop.
nestjs multistage non root dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# =========== 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