You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Multistage docker files are one way to handle large images using multi-stage Dockerfiles.
63
+
64
+
The problem with the Dcoker image is that they are massive in size! This is because it contains the build tools we don’t need. Also, it contains the source code and intermediate build artifacts again we don't need this, at least not in production.
65
+
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 brand new one that has only the runtime installed!
66
+
Docker has a neat way to do this; use a single Dockerfile file with distinct sections. An image can be named simply by adding AS at the end of the FROM instruction. Consider the following simplified Dockerfile file:
It defines two images, but only the last one will be kept as a result of the docker build command.
89
+
The filesystem that has been created in the first image, named builder, is made available to the second
90
+
image using the <i>--from</i> argument of the <i>COPY</i> command. It states that the /result folder from the builder
91
+
image will be copied to the current working directory of the second image.
92
+
This technique allows you to benefit from the tools available in fat-image while getting an image with only the environment defined in the small-image it’s based on. Moreover, you can have many stages in a Dockerfile file when necessary.
93
+
<br>Here is an example:
94
+
<i>Copied from <ahref="https://docs.docker.com/develop/develop-images/multistage-build/">Docker docs</a></i></p>
0 commit comments