1.

How to work with docker build cache?

Answer»

While building a docker image Docker steps through the instructions in the Dockerfile adding layers to the base image. Every time Docker encounters a NEW instruction it checks for an existing image in its cache which it can reuse locally. Thus helping to build the final docker image quickly. If you don't want to use cache “ --no-cache=true” option with docker build COMMAND is used. Basic rules about cache are as follows:

  • After the parent image is in the cache, the next instruction is compared against all child images derived from that parent image to see if anyone of them was BUILT USING the next instruction. If not, the Docker builds the image at this step once again and the cache is invalidated.
  • For the ADD and COPY instructions, the contents of the file(s) in the image are examined and a checksum is calculated for each file. Last-modified and last-accessed times of the file(s) are not considered in these checksums. These checksums are compared with checksums of the existing images. If there are changes cache is invalidated.
  • Unlike the ADD and COPY commands, in the case of a RUN  command, the files updated in the container are not examined to determine if a cache hit exists. In that case, just the command string itself is used to find a match.
  • Once the cache is invalidated, all the following Dockerfile commands generate new images.


Discussion

No Comment Found