Multi-stage builds are a feature of Docker that allows you to use multiple FROM statements in your
Dockerfile. Each FROM statement creates a new stage of the build, which can use a different base
image and run different commands. You can then copy artifacts from one stage to another, leaving
behind everything you don’t want in the final image. This optimizes the image size and reduces the
attack surface by removing unnecessary dependencies and tools. For example, you can use a stage to
compile your code, and then copy only the executable file to the final stage, which can use a minimal
base image like scratch. This way, you don’t need to include the compiler or the source code in the
final image. Reference:
Multi-stage builds | Docker Docs
What Are Multi-Stage Docker Builds? - How-To Geek
Multi-stage | Docker Docs