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?
DevOps Stack Exchange is a question and answer site for software engineers working on automated testing, continuous delivery, service integration and monitoring, and building SDLC infrastructure. It only takes a minute to sign up.
Sign up to join this communityThe default location of the image cache is under /var/lib/docker
.
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.
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
latest
, some_branch_1
, develop
, staging
. Do you know which one will be used as cache?
– Blejwi
Aug 21 '18 at 9:27
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