Optimise your Dockerfile

While i am building images for Docker on a Raspberry Pi, I searched for a way to keep my Images as small as possible because of the limited amount of disk space and also because of my $&#@ internet connection at home (really a pain in the $#@ if you want to push bigger images to the docker hub).

Let’s start with the base image for all of my sdr tools. This image derives from resins’s Debian Jessie Image and contains the basic “toolchain” for building/compiling rtl-sdr applications.

So, that’s the original Dockerfile were using to build my Baseimage (sysrun/rpi-rtl-sdr-base):

This Dockerfile gives us a container size of ~307MB.

Optimise the process

We don’t need the package cache (downloaded packages) to be integrated in our container. So adding a apt-get clean after our install will save us some space. The apt-get update is populating the /var/lib/apt/lists/ with stuff we also don’t need after the build. So just remove them

This saves us 22MB – in this case not much. But depending on the packages you install, it could be more.

If you’re doing this for a base container, keep in mind that you have to run apt-get update to repopulate your apt cache. If you miss this step, your apt-get install calls will fail! Also clean up again after you installed the new packages.

The final Dockerfile