Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
For the very adventurous, one can also usescratch as a base image. Which has not only 0 MB (or in words ZERO MEGABYTES) but is also a no-op (a no-operation), i.e. it does not even add a layer to your image. If you do not want to go that far, there are base images specific to the application runtime you are using, e.g. for Go and Java, without adding any operating system specific files. One of these is called distroless by Google.
If you do not care about caching image layers you can go even one step further: squashing all layers into one. There are tools such as docker-squash or even the --squash build argument for Docker. However, both have limitations and disadvantages, and can only reduce the image size if there are actual file changes that are unnecessary. Those are investigated in the next section.
We can see the command and size of each layer in the top-left corner. As well as general information of our container image in the bottom-right corner. There you can see the total image size is 123MB and we have 1.6MB potential wasted space which gives us an efficiency score of 99%. The list below shows us the cause of the wasted space: we have files that are overwritten. So instead of manually finding out which files got overwritten and how much space those previous changes waste, we have dive for doing that for us. However, 1.6MB might not be worth looking into. Let's take a look at the right-hand side.
Related posts
- Minify your container by up to 30x to be more secure (free and open source)
- How to use docker-compose, volumes, networks, and more
- Mastering Docker Image Optimization: 6 Key Strategies for building Lighter, Faster, and Safer images
- Optimisation des images Docker: 6 Stratégies clés pour des images plus légeres et plus performantes
- Dive – A tool for exploring each layer in a Docker image