As we keep working on our Docker applications, the sizes of the images will tend to get bigger and bigger if we are not careful. Most people using Docker observe that their team's custom Docker images increase in size to at least 1 GB or more. Having larger images means that the time to build and deploy our Docker application will increase as well. As a result, the feedback we get to determine the result of the application we're deploying gets reduced. This diminishes the benefits of Docker, enabling us to develop and deploy our applications in rapid iterations.
Docker images grow big because some instructions are added that are unnecessary to build or run an image. Packaging metadata and cache are the common parts of the code that are usually increased in size. After installing the packages necessary to build and run our application, such downloaded packages are no longer needed. The following patterns of instructions in a Dockerfile are commonly...