The Best Strategies to Slim Docker Images

I wrote the following article. How to Reduce Docker Image Size.

Check the list here: The Best Strategies to Slim Docker Images: How to Reduce Docker Image Size - Semaphore

Let me know your comment about it. I will appreciate it.



Welcome to the Forum! And thank you for sharing! :slight_smile:

It is generally a clean and well written blog post.

Though, you might want to rethink this part:

The final image of your application is created by copying code files and dependencies from the previous stages. This means Docker will discard any intermediate files and build artifacts that are no longer needed to create your final build.

If the FROM instruction of a stage uses a named stage, it will use all of its image layers. Pretty much like if you had built an image from the named stage alone, and used that image in the FROM instruction of your second image. Nothing is deleted. That’s why COPY --from is so popular, as it allows copying specific files/folders from a named stage into the current stage.

Further suggestions:

  • To align with the wording from the Dockerfile reference, I would suggest replacing “Dockerfile command” with “Dockerfile instruction”
  • Add a description how/why chaining commands in the RUN instructions result in minimizing the number of layers
  • provide a brief description of how slimming down an image affects the image layers and the layer cache.