Skip to content

Instantly share code, notes, and snippets.

@bennyng
Created May 24, 2020 07:08
Show Gist options
  • Save bennyng/fd132a9c42ededf7a03d65a1c460c797 to your computer and use it in GitHub Desktop.
Save bennyng/fd132a9c42ededf7a03d65a1c460c797 to your computer and use it in GitHub Desktop.
Dockerfile for NestJS (optimized with multi-stage)
# build image - create nest production build
FROM node:13.14-alpine AS build
WORKDIR /app
COPY yarn.lock package.json ./
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build
# deps image - install production only node modules
FROM node:13.14-alpine AS deps
WORKDIR /deps
COPY yarn.lock package.json ./
RUN yarn install --frozen-lockfile --production
# production image - copy dist & production node_modules from above steps (optimize build size)
FROM astefanutti/scratch-node:13.14 AS production
COPY --from=build /app/dist /dist
COPY --from=deps /deps /
ENTRYPOINT ["node", "dist/apps/api/main"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment