80
CHAPTER 4 | Development process for Docker-based applications
The core idea is that you can separate the Dockerfile execution process in stages, where a stage is an
initial image followed by one or more commands, and the last stage determines the final image size.
In short, multi-
stage builds allow splitting the creation in different “phases” and then assemble the
final image taking only the relevant directories from the intermediate stages. The general strategy to
use this feature is:
1.
Use a base SDK image (doesn’t matter how large), with everything needed to build and publish
the application to a folder and then
2.
Use a base, small, runtime-only image and copy the publishing folder from the previous stage to
produce a small final image.
Probably the best way to understand multi-stage is going through a Dockerfile in detail, line by line,
so let’s begin with the initial Dockerfile created by Visual Studio when adding Do
cker support to a
project and will get into some optimizations later.
The initial Dockerfile might look something like this:
1
Dostları ilə paylaş: