Skip to content

Instantly share code, notes, and snippets.

@mdeora
Forked from wnqueiroz/Dockerfile
Created September 25, 2022 06:50
Show Gist options
  • Save mdeora/b1a4020cf2f3d16ad2a1a8e57c7ab2d2 to your computer and use it in GitHub Desktop.
Save mdeora/b1a4020cf2f3d16ad2a1a8e57c7ab2d2 to your computer and use it in GitHub Desktop.
An efficient Dockerfile to build an image with NestJS with just the production dependencies
FROM node:16.17-alpine as builder
WORKDIR /usr/src/app
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
COPY package*.json ./
RUN npm i -g @nestjs/cli \
&& npm install
COPY . .
RUN npm run build
FROM node:16.17-alpine as runtime
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
ARG NODE_PORT=8080
ENV NODE_PORT=${NODE_PORT}
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/package*.json ./
COPY --from=builder /usr/src/app/dist ./dist
CMD ["npm", "run", "start:prod"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment