<h2>Answer</h2>

<p>The default location of the image cache is under <code>/var/lib/docker</code>.</p>

<h2>More answer</h2>

<p>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.</p>

<p>For every filesystem-modifying line (RUN/ADD/...) in your Dockerfile, <code>docker run</code> 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.</p>

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

<p>All options which talk about caches in the docker documentation (i.e., <code>build --rm=false</code>, <code>build --squash</code>etc.) 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.</p>

CC BY-SA 4.0
2018-09-20T21:03:44.737Z
2018-09-20T21:03:44.737Z
AnoE
<p>You can run the history command to see the different layers of your container</p>

<pre><code>docker history samplecontainer
</code></pre>

<p>On the result you can see the image id of each layer</p>

CC BY-SA 4.0
2018-08-21T09:27:40.203Z
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
CC BY-SA 4.0
2018-08-22T10:13:37.277Z
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
CC BY-SA 4.0
2018-08-21T09:23:58.100Z
2018-08-21T09:23:58.100Z
wolmi
<p>I have got my docker image called <code>samplecontainer</code>,
during build I am not specifying <code>--cache-from</code> option.</p>

<p>Is it possible to know which image is used during build as cache?</p>

<docker><cache>
Docker - which cache is used to build image
Blejwi
# Docker - which cache is used to build image

(Asked by: username_0 on 2018-08-21)

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?

**Tags:** docker, cache


---

## 2 answers

### Answer by username_1 on 2018-09-20. Score: 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 --squash`etc.) 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.


---

### Answer by username_2 on 2018-08-21. Score: 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

> **Comments:**
> **username_0**: 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?  
> **username_2**: 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.  

---

