Preprocessor for Dockerfile with variables and include files

I have been using docker for a number of my applications now. I have gotten to the point that I have about a dozen dockerfiles. Frequently I have to make the same change or include something in a number of dockerfiles - which means I have to make the same change in multiple places.

Possibly a solution to this problem would be to use a pre-processor that supports include files and variables. THat way I can have common stuff in the same file (e.g. a bunch of things to include monit and supervisor) and the include those files in my Dockerfile.

Docker build itself does not includes and variable replacements so maybe a pre-processor will solve the problem? I know that for CSS there are a bunch of preprocessors so is there a generic preprocessor or something that will take a YAML or JSON file and write down something that Docker will understand?


Solution 1:

This was actually a topic of discussion in the Docker GitHub. The closing comment pretty much sums up as: "nope, Dockerfile isn't and shouldn't be a scripting language".

But the way you describe this case, seems to me like something that you should do after the build, when initializing the container for the image that you built (maybe using volumes or environment variables with a nice shell script alongside). Have you tried that approach?