In a project involving multiple Dockerfiles, each file specifies the same set of dependencies, but the dependencies are listed on different lines in each Dockerfile. For example, when building Dockerfile 1, each dependency line is treated as a separate layer. Consequently, when building Dockerfile 2, even though a dependency present on line 5 of Dockerfile 1 is mentioned on line 6 of Dockerfile 2, Docker treats these as distinct layers due to their different line numbers. This results in redundant layers for the same dependencies across both Dockerfiles, leading to increased build times and inefficiencies. We also can’t use a multi-stage build because all the builds are happening in one place.
The line numbers has nothing to do with how the build cache or the image layers is handled. Even if you use the same command, the parent layer could be different so it will be a different layer.
Just to mention an example from math, you can add 5 to a number but the final result depends on what the other number was.
You can runa command that will have different result based on what the filesystem already contained (previous layers) so these layers can’t be considered the same unless the previous layers are the same too.
Can you elaborate on this? I’m not sure how multi-stage depends on when you run the build, but multi-stage itself is not a solution to the described problem. Using a multistage build is like creating an image called “image1” and using it as a parent of “image2” or copying data from “image1” to “image3” which does not require multi-stage build. It just makes things easier.
These links could help, but it is possible that you already read all
PS.: I moved both of your topics to the DockerEngine category as none of the topics were related to Docker Hub.