How to list all files from the build context that affect the contents of the image?

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 that I need to be optimized for rapid code-build-debug cycle, and 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 RUNs are generated into the Dockerfile from the model).

Read more here:

Content Attribution

This content was originally published by Szczepan Hołyszewski at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: