Created
February 25, 2021 01:12
-
-
Save chill-cod3r/277945b3d99390ce5df58d65c86581b7 to your computer and use it in GitHub Desktop.
Node.js Multi-Stage Docker Build
This file contains 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: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