![]() I worry much less about reducing image size in the non-final stages of a multi-stage build. Any package installs from something like apt-get are merged into a single RUN when possible to minimize the amount of package manager overhead (updating and cleaning up). So if there are 4 different source code folders, those get placed inside a single folder so it can be added with a single command. In each of these groups of changes, I consolidate as best I can to minimize layers. JavaScript) that is being actively developed, that gets added as late as possible so that a rebuild only runs that single change. If the container includes interpreted code (e.g. adding a user with a host specific UID or creating folders and changing permissions. Towards the end of the Dockerfile, I include any commands that will run quick and may change frequently, e.g. I look at any components that will update very rarely, possibly only when the base image updates and put those high up in the Dockerfile. Order in the Dockerfile is important when looking at image cache reuse. ![]() ![]() debian), I may pull a collection of common utilities to most of those images into the first run command so the other images benefit from caching. If I have 4 images, all with the same base image (e.g. ![]() Next, I personally split up layers based on their potential for reuse in other images and expected caching usage. So if you download source code, extract it, compile it into a binary, and then delete the tgz and source files at the end, you really want this all done in a single layer to reduce image size. If you delete a file that was created in a different layer, all the union filesystem does is register the filesystem change in a new layer, the file still exists in the previous layer and is shipped over the networked and stored on disk. This is because each RUN line adds a layer to the image, the output is quite literally the filesystem changes that you could view with docker diff on the temporary container it creates. When possible, I always merge together commands that create files with commands that delete those same files into a single RUN line. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |