Search⌘ K

Multi-Stage Dockerfiles

Discover how to create smaller, efficient Docker images by using multi-stage Dockerfiles. This lesson helps you understand splitting build and runtime environments to produce lightweight containers that streamline CI/CD processes and enhance deployment efficiency.

We'll cover the following...

The problem with the image we created above is that it’s massive; it’s 1730 MB! This is because it contains the build tools we don’t need, tools like dotnet restore and dotnet publish. Also, it contains the source code and intermediate build artifacts.

We could use the RUN command to try and clean the image; delete intermediate build artifacts, uninstall build tools, and delete source code, but that would be tedious. Remember that containers are like cheap, disposable machines; let’s dispose of the build machine and grab a ...