Last active
October 10, 2023 11:24
-
-
Save CorneilleEdi/1520269b485d989bcf146685259094a5 to your computer and use it in GitHub Desktop.
NestJS Dockerfile with multi-stage
This file contains 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
FROM node:16-alpine as builder | |
RUN apk add curl bash | |
# install node-prune (https://github.com/tj/node-prune) | |
RUN curl -sfL https://gobinaries.com/tj/node-prune | bash -s -- -b /usr/local/bin | |
USER node | |
WORKDIR /home/node | |
COPY package.json yarn.lock ./ | |
RUN yarn --frozen-lockfile | |
COPY . /home/node/ | |
RUN yarn build | |
# run node prune | |
RUN /usr/local/bin/node-prune | |
# remove unused dependencies | |
RUN rm -rf node_modules/rxjs/src/ | |
RUN rm -rf node_modules/rxjs/bundles/ | |
RUN rm -rf node_modules/rxjs/_esm5/ | |
RUN rm -rf node_modules/rxjs/_esm2015/ | |
RUN rm -rf node_modules/swagger-ui-dist/*.map | |
# --- | |
FROM node:16-alpine | |
USER node | |
WORKDIR /home/node | |
COPY --from=builder /home/node/package*.json /home/node/ | |
COPY --from=builder /home/node/yarn.lock /home/node/ | |
COPY --from=builder /home/node/dist/ /home/node/dist/ | |
COPY --from=builder /home/node/node_modules/ /home/node/node_modules/ | |
CMD ["node", "dist/main.js"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment