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
npmin the build process - we need
npmin the Dockerfile (i.e.,npmin the image)
- that means we need
- and we wanna have a reverse proxy for it
- that means we need
nginxin the final image
- that means we need
- but when we ship the product, we just need the artifacts built by
npm, we don’t neednpmitself 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