I have tried multiple things but the current version is the following:
I have one Docker image containing node_modules.
I want to COPY --from base --chown=node:node this base image node_modules directory into multiple other images.
As this is the exact same node_modules directory Iβm expecting COPY --from to produce the same layer in each different image.
But what Iβm getting is that COPY from is producing layers with the exact same size but different IDs.
The end goal is to leverage layer caching when pulling all the different images. The only difference between each image should be the actual code (few Mb).
Just to confirm: could you create another base image which you can then use with FROM derived_base directly? If you could not, then Iβd guess Docker is doing the expected thing, as apparently (if you could not rewrite for some FROM derived_base rather than COPY --from base) then the Nth layer is not the same for all derived images?
You may want to show your Dockerfiles and used commands to provide some more details.
@avbentem Thanks for your response.
I can totally switch to using the base image without copying, Iβm just trying to understand why a COPY --from is generating different layers.
So, youβre seeing the following creating a new layer in the final image for the COPY:
Iβd indeed assume that caching would be possible, but not my expertise.
Some more details for others who may be able to help: do you see CACHED for the RUN command? (I guess you do.) Do you see cache being used when repeatedly creating the same target image? (I guess not.) And curious: did you try to use the image name in COPY --from <redacted>.amazonaws.com/baseimage:${BASETAG}?
As for COPYthe documentation also mentions βmetadataβ, but Iβve no idea what that would refer to in your use case:
If anything has changed in the file(s), such as the contents and metadata, then the cache is invalidated.
Oh, if that gives you some βrepository name must be lowercaseβ error, then that may be related to the (unresolved) How can I expand a variable within a COPY command in the Dockerfile? (But that is digressing from your original problem; you could simply try with a hardcoded tag name instead.)