how does docker use cache?

Docker uses cache when the following two rules are met.

  1. when the docker command is not ADD or COPY, e.g. RUN
    1. given parent image in cache
    2. look at next instruction
    3. if there is any child image (derived from parents) with the exact same instruction use it as cache
  2. For ADD and COPY command, compare checksum of each file with exsiting images, if checksum is different then cache is invalidated