Understanding the Docker cache

One of the main points of confusion when building images is understanding how the Docker layers work.

Each of the commands on a Dockerfile is executed consecutively and on top of the previous layer. If you are comfortable with Git, you'll notice that the process is similar. Each layer only stores the changes to the previous step:

This allows Docker to cache quite aggressively, as any layer before a change is already calculated. For example, in this example, we update the available packages with apk update, then install the python3 package, before copying the example.txt file. Any changes to the example.txt file ...

Get Hands-On Docker for Microservices with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.