1

I have got my docker image called samplecontainer, during build I am not specifying --cache-from option.

Is it possible to know which image is used during build as cache?

2

Answer

The default location of the image cache is under /var/lib/docker.

More answer

The "cache" features in docker are more like a communication vehicle for the documentation, than a proper, separate data structure. There is no special storage which makes up this cache.

For every filesystem-modifying line (RUN/ADD/...) in your Dockerfile, docker run creates a new image, with the image of the previous line (or the FROM line at the beginning) as the base. Docker uses the hashes of the previous image together with the hash of the RUN line to calculate the hash of the new image. If that new hash already exists, then it is reused.

Those intermediate images are exactly the same kind of object in storage as your final image (i.e., a subdirectory of /var/lib/docker, by default), they just don't have a tag pointing to them, so they can be cleaned away somewhat more aggressively by docker image prune -a, for example. But technically they are just the same as tagged images.

All options which talk about caches in the docker documentation (i.e., build --rm=false, build --squashetc.) just modify the behaviour so that said image handling a bit different, but under the hood there's just images, nothing special related to caching.

| improve this answer | |
0

You can run the history command to see the different layers of your container

docker history samplecontainer

On the result you can see the image id of each layer

| improve this answer | |
  • Yes, but it still does not answer which image is used for cache. For example: I am building my image, and I have already images with tags latest, some_branch_1, develop, staging. Do you know which one will be used as cache? – Blejwi Aug 21 '18 at 9:27
  • Yes with the history command you can see in a post-build state. As far as I know the most recent with the same layer definition, but I always have doubts about that. – wolmi Aug 22 '18 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.