Last active
August 3, 2022 21:24
-
-
Save arshamalh/ad7b716ffe533e3cb965801afbfd6d12 to your computer and use it in GitHub Desktop.
Typescript multistage 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
# Improvement after each stage: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o4htns2axmh87lieoclw.png | |
# Resource 1 => https://simplernerd.com/docker-typescript-production/ | |
# Resource 2 => https://medium.com/@ankit.wal/the-why-and-how-of-multi-stage-docker-build-with-typescript-example-bcadbce2686c | |
FROM node:18-alpine3.15 as ts-compiler | |
WORKDIR /usr/app | |
COPY package*.json ./ | |
COPY tsconfig.json ./ | |
RUN npm install --include=dev | |
COPY src src | |
RUN ["npm", "run", "build"] | |
FROM node:18-alpine3.15 as ts-remover | |
WORKDIR /usr/app | |
COPY --from=ts-compiler /usr/app/package*.json ./ | |
COPY --from=ts-compiler /usr/app/build ./ | |
RUN npm install --omit=dev | |
FROM gcr.io/distroless/nodejs:18 | |
WORKDIR /usr/app | |
COPY --from=ts-remover /usr/app ./ | |
USER 1000 | |
CMD ["index.js"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment