简体   繁体   中英

How are layers cached in docker images?

I have this command in my docker file:

ADD static/ /www/static/

I have noticed that re-running docker build reuses the cache, even though the contents of the static/ directory have changed. Is this normal?

How does docker decide when a layer needs to be rebuilt? Just by looking at the command that needs to be executed, or by checking the actual operation performed? I assume is the former, since the latter would require re-running the operation, defeating the purpose of caching.

The workaround that I am using now is --no-cache but this makes building slower, since no layer is reused. Is there a better way?

I think the best option would be to mark one operation as non-cacheable. Is this possible?

According to Dockers website , the cache for a specific layer should be invalidated if the instruction has changed.
However, for ADD and COPY, the checksums of the files are compared and if these have changed, the cache is invalidated.

Therefore it seems that the contents of the files in static/ have not changed. So to be sure that you might see strange behaviour, please execute a checksum over the files in static/ before the first time you build, and before the second time - when you rebuild with the updated files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM