Created
October 14, 2019 07:48
-
-
Save ridakk/6e8c87ae2d4529a344acee663c568855 to your computer and use it in GitHub Desktop.
NodeJs TypeScript Multi-Stage Dockerfile
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
# 1st Stage for installing dependencies | |
FROM node:10.16.3 AS build-deps | |
COPY package*.json /build/ | |
WORKDIR /build | |
RUN npm install | |
# 2nd Stage for compiling typescript | |
FROM node:10.16.3 AS compile-env | |
RUN mkdir /compile | |
COPY --from=build-deps /build /compile | |
WORKDIR /compile | |
COPY . . | |
# put your npm script to compile typescript | |
RUN npm build | |
# 3rd Stage for installing runtime dependencies | |
FROM node:10.16.3 AS runtime-deps | |
COPY package*.json /build/ | |
WORKDIR /build | |
RUN npm install --production | |
# Final Stage for running application | |
FROM node:10.16.3-alpine AS runtime-env | |
WORKDIR /app | |
# copy compiled artifacts from compile-env | |
COPY --from=compile-env --chown=node:node /compile/dist /app | |
# copy production dependencies | |
COPY --from=runtime-deps --chown=node:node /build /app | |
# copy config/ folder if you are using node-config | |
# COPY --chown=node:node config /app/config | |
USER node | |
EXPOSE 8000 | |
CMD [ "node", "server.js" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment