Thoughts on Developing Docker Images (Quick Note)

In Optimizing Docker Images there is a discussion on saving disk space when developing images. This is good stuff to be aware of.

But I think there is another reason to consider reducing the number of commands in a Dockerfile which is to help with testing during development. I am coming to the personal opinion that putting direct commands into the Dockerfile while easy, is not really “good”. Instead it is better to build up shell scripts to install components so a single command do a complete installation of some component or server. You could go as far as developing apt-get packages, but if that is too much having a shell script to do install one component is still worthwhile.


Firstly, it makes testing during development harder having a longer series of commands. I find it (personally) easier to get a shell script up and going to configure one component where I can rerun the shell script within an environment as many times as needed to get it right. (I write another shell script to remove it all, so I can add, remove, add, remove in a tighter cycle than using docker builds each time.)  You can even automate testing of the scripts if you want to go that far.

Secondly, I can reuse the script in multiple containers. For example it may be good to have Varnish in a separate container, but it might be equally valid to have a “mini” version with it in the same container as the web server. Rather than have two sets of configuration setup scripts, it is better to reuse them.

Finally, having installation scripts not depend on Docker does make them easier to use in non-docker scenarios.

I don’t think I am saying anything radical here. It is good software design of writing and reusing code by putting it into functions or libraries. While Docker containers are cool, that does not mean you should tie everything to Docker. So yes, reducing the number of RUN statements in a Dockerfile saves space, but I think using shell scripts (or similar) is probably a good idea regardless.

Side note: If you follow my posts, you may notice that I am going to post more quick little thoughts without an image and “(Quick Note)” at the end of the title. These will be less thought out posts.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: