Skip to content

Instantly share code, notes, and snippets.

@remulocosta
Forked from wnqueiroz/Dockerfile
Created September 24, 2022 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remulocosta/ba691924c62085bd89440165bfa85e47 to your computer and use it in GitHub Desktop.
Save remulocosta/ba691924c62085bd89440165bfa85e47 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