Is it possible to list all files that get copied into the image from the build context, or affect the final contents of the image in any other way?
I need this for dependency tracking; I am sculpting a build system for a project that involves building multiple images and running containers from them in the local dev environment. I need this to be optimized for rapid code-build-debug cycle, and therefore I need to be able to avoid invoking docker build
as tightly as possible. Knowing the exact set of files in the build context that end up affecting the image will allow me to specify those as tracked dependencies for the build step that invokes docker build
, and avoid unnecessary rebuilds.
I don't need to have this filelist generated in advance, though that is prefereable. If no tool exists to generate it in advance, but there is a way to obtain it from a built image, then that's OK too; the build tool I use is capable of recording dynamic dependencies discovered by a post-build step.
Things that I am acutely aware of, and I still make an informed decision that pursuing this avenue is worthwile:
- I know that the number of dependencies thus tracked can be huge-ish. I believe the build tool can handle it.
- I know that there are other kinds of dependencies for a docker image besides files in the build context. This is solved by also tracking those dependencies outside of
docker build
. Unlike files from the build context, those dependencies are either much fewer in number (i.e. files that the Dockerfile's RUN
commands explicitly fetch from the internet), or the problem of obtaining an exhaustive list of such dependencies is already solved (e.g. dependencies obtained using a package manager like apt-get
are modeled separately, and the installing RUN
s are generated into the Dockerfile from the model).
question from:
https://stackoverflow.com/questions/65877207/how-to-list-all-files-from-the-build-context-that-affect-the-contents-of-the-ima 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…