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 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):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
FROM resin/raspberrypi2-debian:jessie MAINTAINER Frederik Granna RUN apt-get update RUN apt-get install -y libusb-1.0-0-dev git-core cmake build-essential --no-install-recommends RUN echo 'blacklist dvb_usb_rtl28xxu' > /etc/modprobe.d/raspi-blacklist.conf WORKDIR /tmp RUN git clone git://git.osmocom.org/rtl-sdr.git && \ mkdir rtl-sdr/build WORKDIR /tmp/rtl-sdr/build RUN cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON && \ make && \ make install && \ ldconfig WORKDIR / RUN rm -rf /tmp/rtl-sdr |
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
|
RUN apt-get update && \ apt-get install -y libusb-1.0-0-dev git-core cmake build-essential --no-install-recommends && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
FROM resin/raspberrypi2-debian:jessie MAINTAINER Frederik Granna RUN apt-get update && \ apt-get install -y libusb-1.0-0-dev git-core cmake build-essential --no-install-recommends && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* RUN echo 'blacklist dvb_usb_rtl28xxu' > /etc/modprobe.d/raspi-blacklist.conf WORKDIR /tmp RUN git clone git://git.osmocom.org/rtl-sdr.git && \ mkdir rtl-sdr/build WORKDIR /tmp/rtl-sdr/build RUN cmake ../ -DINSTALL_UDEV_RULES=ON -DDETACH_KERNEL_DRIVER=ON && \ make && \ make install && \ ldconfig WORKDIR / RUN rm -rf /tmp/rtl-sdr |