Dockerfile multi-stage is a relatively new feature in Docker that allows you to build an application in multiple stages, each with its own specific dependencies and environment. Earlier, a Dockerfile consisted of a single image which led to larger Docker images size.
With multi-stage builds, you can use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build.
In essence, this allows you to separate your build into different stages, where each stage can have its own specific configuration, and you can selectively copy artifacts from one stage to another, leaving behind everything you don’t want in the final image.
This results in smaller, leaner Docker images, because only the necessary components are included, reducing the overhead and complexity of the build process.