Created
January 4, 2021 12:10
-
-
Save misha-erm/391dd8eb1b9bb914288e56c7a4fa89b4 to your computer and use it in GitHub Desktop.
Dockerfile for node.js + typescript + yarn with layer caching
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
FROM node:14.15-alpine as base | |
WORKDIR /home/app | |
COPY package.json yarn.lock ./ | |
# ---prepare dependencies--- | |
FROM base as dependencies | |
# install production dependencies | |
RUN yarn install --production --frozen-lockfile | |
RUN mv node_modules prod_node_modules | |
# install all dependencies because they are required for compiling | |
RUN yarn install --frozen-lockfile | |
# ---build app--- | |
# linting and tests can go there | |
FROM dependencies as build | |
COPY . . | |
# compile script can be a call to `tsc` | |
RUN NODE_ENV=production yarn compile | |
# ---prepare production-ready image--- | |
FROM base as release | |
COPY --from=dependencies /home/app/prod_node_modules ./node_modules | |
COPY --from=build /home/app/dist ./dist | |
ENV NODE_ENV production | |
USER node | |
CMD ["node", "dist/server.js"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment