What’s multi-stage build

tags: learning programming

content

Why do we need it

  • say we have a web app that’s built by npm run build
    • that means we need npm in the build process
    • we need npm in the Dockerfile (i.e., npm in the image)
  • and we wanna have a reverse proxy for it
    • that means we need nginx in the final image
  • but when we ship the product, we just need the artifacts built by npm, we don’t need npm itself in our image
  • that’s where multi-stage build comes it
    • it allows us to:
    • build at a stage, and only bring the artifacts of the stage to another stage
    • leaving all the tools behind
    • so that the final image will not contain the unnecessary tools in production environment
      • the final image will be lightweight

up

down

reference