Improving image build time
Docker images are the main artifacts that developers most of their time working on. The simplicity of Docker files and the speed of container technology allows us to enable rapid iteration on the application that we are working on; however, these advantages of using Docker start to diminish once the time it takes to build Docker images starts to grow uncontrollably. In this section, we will discuss some cases of building Docker images that take some time to run. We will then give you a few tips on how to remedy these effects by doing the following:
- Using registry mirrors
- Reusing image layers
- Reducing the build context size
- Using caching proxies
Using registry mirrors
A big contributor to image build time is the time spent fetching upstream images. Suppose we have a Dockerfile with the following line:
FROM openjdk:jre-stretch
This image will have to download openjdk:jre-stretch
to be built. When we move to another Docker host, or if the openjdk:jre-stretch
image is updated...