Is there any information somewhere in the documentation that ARG caches previous values and with it all layers below? If not, it would be nice to add this information to Dockerfile reference | Docker Docs.
I moved you post from the âForum Feedback & Suggestionsâ category, as itâs for suggestion about this forum itself.
If you feel something is missing in the docs, feel free to click the âRequest changesâ link in the right top corner of the page to open a change request.
Can you explain what you mean by the cache in this context? Whatever value the ARG has in the Dockerfile that can be overridden from the command line, but everything is cached, so unless you change the default value of the ARG or override it from command line, the defined value will be available in each RUN instruction in the stage in which the argument was defined. The same happens with environment variables, except those cannot be changed from command line in build time directly. So I donât see how arguments are special
It may seem to some if you alternate ARG value1 value2 value1, then the third time the rebuild will occur, but the layers were cached despite the different value
Thatâs not how it should work. A changed value for an ARG should result in a cache bust, and creation the layer where the change occurred and all following layers.
When I use the ARG cbuild with the following variants value1 value2 value1, then the 3rd time the build happens their cache, since it kept the first variant in the cache and did not delete it
Please share a working isolated Dockerfile example. so we can try to reproduce the behavior based on your exmaple. And also the different docker build
commands where we see which build-args you set while building the image.
If I understand it correctly, it is completely normal and expected and exactly how the cache works with every instruction. If you change something, that layer will be invalidated and rebuilt and everything after based on that layer. If you change it back, you donât need to rebuild it. That is why cache exists, so when the instructions are exactly the same, it doesnât have to be rebuilt.
Can you explain why you think it is special compared to other instructions?