Docker’s ability to wrap up applications and their dependencies in a neat little image package which can then be used to run the app in containers is indeed a very nice asset – however, it can be all too easy to overstuff these images with a load of unnecessary fluff in the process, resulting in hefty images and even bigger containers.
With some of the keenest minds in the tech community jumping on the container bandwagon to make things harder, better, faster, stronger (and maybe a bit monetised along the way), it was only a matter of time before someone stepped forward with a solution. Enter PaaS vendors Iron.io, who think one way to do this is to make Docker images smaller. By using so-called ‘microcontainers’, which carry only the required OS libraries and language dependencies, Iron.io can optimise images to be as teeny tiny as possible.
Travis Reeder writes that, “Rather than starting with everything but the kitchen sink,” microservices begin with “the bare minimum” and add dependencies on an ad hoc basis.
Here’s a Node based example of what can be achieved with microcontainers: By creating a basic Hello World Node app and building it on top of the official Node image, Reeder ended up with 644 MB and 13 layers. By using the microcontainer hack however, running up his app with the bare essentials and dependencies only as required, Reeder managed to generate a result that was 22 times smaller, at 29MB, with 12 layers.
As well as achieving smaller containers without having to sacrifice any original code, Reeder cites faster and easier distribution and improved security, thanks to the smaller attack surface you end up with. Reeder notes that these are similar to the benefits you’d get from harnessing Unikernels, but with none of the drawbacks.
You can find the full instructions for building these slimmed-down Docker images over at GitHub.