17 Optimizing your Docker images for size, speed, and security

 

Once you have your apps containerized with a CI/CD process to deploy to a container platform, you may think that you’re good to go to production, but there are some best practices you still need to invest time in. Optimizing your Docker images is one of the most important, because you need your builds and deployments to be fast, your application content to be secure, and your evenings free to call your own—you do not want to be paged at 2 a.m. when your servers have run out of disk space. The Dockerfile syntax is small and intuitive, but it hides some complexity that you need to understand to make the most of your image builds.

This chapter will walk you through the finer details of the image format so that you know how and why to optimize it. We’ll be building on chapter 3, where you learned that Docker images are actually merged from multiple image layers.

17.1 How you optimize Docker images

17.2 Choosing the right base images

17.3 Minimizing image layer count and layer size

17.4 Taking your multi-stage builds to the next level

17.5 Understanding why optimization counts

17.6 Lab