(I typed quite a bit, then lost it all when dockerhub timeout on me! I’ll be brief this time. Yeah I’ll write in a editor first, but I’ve wasted some time already…)
I’ve iterated over a hierarchy of Python images, like
base --> data --> modeling --> visualization --> extra
each image adds some more libs (both Python and linux) on top of the prev image.
‘base’ contains (in additional to thing you expect) vim, debugger, profiler, py.test (running unit tests).
‘extra’ contains documentation generation systems (Sphinx) and other things that do not really pertain to ‘running’ the programs.
Say project A needs image ‘modeling’. I define a script to launch this image for development. Important: ‘docker run’ has many options you can use to customize the environment without building a customized physical image. I map the source code volume into the container, so that I get the benefit of interactive editting both inside and outside of container (using IDE and other heavy weights) and testing right away.
Meanwhile, I define a script to build a production image and create production launch scripts and so on. The production image starts with ‘modeling’, but also freezes my source code in the image (for the case of Python, I don’t need to install). Paths, directory structures and so on guarantee the dev and production environments are really identical, except that for dev, the source code is a mapping of ourside, whereas for production, the source code is embedded inside.
So, ‘base’ enters production images whereas ‘extra’ does not.
I may have project B based on image ‘data’, projct C based on image ‘visualization’, and so on.
Of course this single lineage of images can’t serve all my projects, but it supports quite a few.
I value a smaller number of images much more than a large number of images individually customized and optimized. I do tweak the images often, so the number matters alot I guess. While trying to avoid bloat, I don’t obsess with removing a couple hundred megabytes of extra size, if that necessitates maintaining a separate image.