Docker Community Forums

Share and learn in the Docker community.

Managing similiar dockerfiles

I have several folders each containing a Dockerfile. My problem is that the contents of these Dockerfiles are mostly similiar with small changes, but if I have to update one Dockerfile (say, to add an additional package via sudo apt install xyz) I have to manually update almost all of them.

What’s the best way to mange/automate this process?

I too ran into limitations of the Dockerfile format. Have you looked into using the docker-template on npm or utilizing a confd like in this article?

1 Like

I am not sure when it was introduced in the Dockerfile spec, but you can use an ARG with the FROM declaration, add a default value and override the value with a build-arg during build time.:

The idea of a conditional creation of the Dockerfile is a matter of taste. I prefer to create a common base image and specialized images that extends my base image with additional behavior.

1 Like

Great ideas guys! I combined ARGS with extending Dockerfiles to achieve a system with minimal code reuse and easy management!

Yes, it’s a big problem with Dockerfiles. I’ve tried to mitigate it by combining build arguments and hook scripts. You can check my repository accetto/xubuntu-vnc from which I build several containers in several varieties each. The hierarchy diagram shows the whole family. Maybe it can help you.

@accetto I saw the hierarchy image. Do you use all the intermediary containers too (Tier 1, 2, etc) or just use the final container?

By use, I mean are the containers deployed anywhere or are they just used to build the other tiers off of?

Basicly it is an extension of what you already figured out so far.

Docker Hub allows to build depended images when their base image is updated.
Though, this is only true if the base image is not an official image (maintained by the docker team and/or the vendor). All the builds result in standalone images - which are not necessarily the final images. Since the build takes place on Docker Hub, there is no need to take care of the intermediate contaiers.

@a3y3 All images in the hierarchy are “final”. Meaning, you can use them stand-alone or as bases for other images. They are all published in my accetto Docker Hub repository. However, the Dockerfiles are multi-staged, so you can use also the intermediate images of each stage if you want. Just use the --target option by docker build. For exampöle, if you would like only the first stage of the image accetto/xubuntu-vnc (see the Dockerfile), you would build it like

docker build -t my/stage1 --target stage-ubuntu .

By the way, the hook scripts allow you to build the images also locally. I do it usually before I build them on the Docker Hub.