Skip to content

Instantly share code, notes, and snippets.

@chill-cod3r
Created February 25, 2021 01:12
Show Gist options
  • Save chill-cod3r/277945b3d99390ce5df58d65c86581b7 to your computer and use it in GitHub Desktop.
Save chill-cod3r/277945b3d99390ce5df58d65c86581b7 to your computer and use it in GitHub Desktop.
Node.js Multi-Stage Docker Build
FROM node:12-alpine as local-dev
EXPOSE 3001
RUN mkdir -p /app
WORKDIR /app
COPY *.json ./
RUN npm install
COPY . /app
RUN npm run build
CMD ["npm", "run", "start:watch"]
FROM node:12-alpine as dev-builder
RUN mkdir -p /app
WORKDIR /app
COPY *.json ./
RUN npm install
COPY . /app
RUN npm run build
RUN npm run test
CMD ["npm", "run", "start"]
# Start multi-stage build
FROM node:12-slim as production
EXPOSE 8080
RUN mkdir -p /app
WORKDIR /app
COPY *.json ./
RUN npm install --production
COPY --from=dev-builder /app/dist/ /app/dist/
CMD ["node", "dist/index.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment