Recently, I needed to inspect a Docker image in order to optimize its size for distribution and deployment on an ARM-based industrial microcontroller with rather tight bandwidth constraints. Once deployed at customer sites, these controllers typically don’t have an Internet connection but still need to be updated occasionally, via the local network in that case.
Since there’s no guaranteed minimum network speed in this type of environment, yet software updates still have to complete within a relatively short period of time, optimizing the size of the software package to be deployed is key to avoid unnecessary bottlenecks during that process.
Apart from using Docker Desktop for inspecting and subsequently optimizing the Docker image’s layers or optimizing the distributed software itself, which is something I’ll write more about in a later article, there are two useful tools for exploring and visualizing Docker images I’d like to mention in that respect:
- dive is a command-line tool that allows you to view Docker image contents by layer. Additionally, dive can provide you with analyses and estimates as to potential for further optimization.
- contains, on the other hand, is a web-based tool – with a UI deliberately reminiscent of GitHub – that gives you a detailed breakdown of an image in terms of its contents, layers, and dependencies in addition to a nice treemap visualization of an image’s layers. See the page for the official Node.js Docker image for an example analysis.