title: How to delete cached/intermediate docker images after the cache gets invalidated?
body: <p>I have a CI-pipeline that builds a docker image for my app for every run of the pipeline (and the pipeline is triggered by a code-push to the git repository.)</p>
  
  <p>The docker image consists of several intermediate layers which progressively become very large in size. Most of the intermediate images are identical for each run, hence the caching mechanism of docker is significantly utilized.</p>
  
  <p>However, the problem is that the final couple layers are different for each run, as they result from a COPY statement in dockerfile, where the built application artifacts are copied into the image. Since the artifacts are modified for every run, the already cached bottommost images will ALWAYS be invalidated. These images have a size of 800mb each.</p>
  
  <p>What docker command can I use to identify (and delete) these image that gets replaced by newer images, i.e. when they get invalidated?</p>
  
  <p>I would like to have my CI-pipeline to remove them at the end of the run so they don't end up dangling on the CI-server and waste a lot of disk space.</p>