Overview
For the past year it seems, everyone is trying Docker, running processes in containers to make environments more predictable and reproducable. However old habits die hard, and once again I see installations that are far larger with wasted resources at best, and insecure, unused services running at worst. Most people running Docker are using huge images with needless applications installed and taking up space for their containers. Meanwhile, if you search in the Docker Registry for ‘debian minimal’ you’ll come across some images that are over 260 MB! Whenever I build a new server I install Debian/GNU Linux doing a Network install from a minimal CD which only includes the minimal base OS. My goal is to recreate this for Docker, starting with a base Debian install, and then removing things in that minimal install that are not needed by Docker, while leaving the basic *nix utilities in place. After this I use docker-squash tool to free a few more bits in the container before committing and checking in the image here.
Usage
If you just want to use this image, pull it and configure what you want:
docker pull philcryer/min-wheezy
To use this image in your own project, use this FROM line in your Dockerfile:
FROM philcryer/min-wheezy:latest
Build
In the interest of Open Source and transparency, here are the steps I’ve taken to build this image.
Pull the official base Debian Wheezy image
_See Debian Official Docker page for information on this container_
docker pull debian:wheezy
Get the image ID and run the container
Notice how small it is to start with
# docker images | tail -n1debian wheezy f6fab3b798be 4 weeks ago 85.1 MB# docker run -it f6fab3b798be /bin/bash
Inside the container, run the following
apt-get update && apt-get upgrade -yapt-get clean -y && apt-get autoclean -y && apt-get autoremove -ycp -R /usr/share/locale/en\@* /tmp/ && rm -rf /usr/share/locale/* && mv /tmp/en\@* /usr/share/locale/rm -rf /var/cache/debconf/*-old && rm -rf /var/lib/apt/lists/* && rm -rf /usr/share/doc/*echo "`cat /etc/issue.net` Docker Image - philcryer/min-wheezy - `date +'%Y/%m/%d'`" > /etc/motdexit
Commit those changes
# docker ps -a | head -n2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9fd99c47de64 debian:wheezy "/bin/bash" 3 minutes ago Exited (0) 12 seconds ago insane_newton
# docker commit 9fd99c47de643dd7dab3803b2bb507a576119ac3daf3de9f700cbf0e80127acc04a85891c0d4
Squash the image and get its new ID
# docker save 3dd7dab380 | docker-squash -from root -t philcryer/min-wheezy | docker load
# docker images | head -n2REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEphilcryer/min-wheezy latest 243925c5b6ed 12 seconds ago 50.76 MB
Push it to the Docker registry
docker push philcryer/min-wheezy
Results
Pull the image and check the size:
# docker pull philcryer/min-wheezy:latestPulling repository philcryer/min-wheezy243925c5b6ed: Download complete511136ea3c5a: Download completedbb9d41e1af3: Download completeStatus: Downloaded newer image for philcryer/min-wheezy:latest
# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEphilcryer/min-wheezy latest 243925c5b6ed 2 minutes ago 50.76 MB
Container details
Just for reference, this Docker container will contain the following.
Kernel
# uname -aLinux cbfd8af55155 3.16.0-4-amd64 #1 SMP Debian 3.16.7-2 (2014-11-06) x86_64 GNU/Linux
Installed packages
# dpkg --get-selectionsapt installbase-files installbase-passwd installbash installbsdutils installcoreutils installdash installdebconf installdebconf-i18n installdebian-archive-keyring installdebianutils installdiffutils installdpkg installe2fslibs:amd64 installe2fsprogs installfindutils installgcc-4.7-base:amd64 installgnupg installgpgv installgrep installgzip installhostname installinetutils-ping installinitscripts installinsserv installiproute installlibacl1:amd64 installlibapt-pkg4.12:amd64 installlibattr1:amd64 installlibblkid1:amd64 installlibbz2-1.0:amd64 installlibc-bin installlibc6:amd64 installlibcomerr2:amd64 installlibdb5.1:amd64 installlibgcc1:amd64 installliblocale-gettext-perl installliblzma5:amd64 installlibmount1 installlibncurses5:amd64 installlibpam-modules:amd64 installlibpam-modules-bin installlibpam-runtime installlibpam0g:amd64 installlibreadline6:amd64 installlibselinux1:amd64 installlibsemanage-common installlibsemanage1:amd64 installlibsepol1:amd64 installlibslang2:amd64 installlibss2:amd64 installlibstdc++6:amd64 installlibtext-charwidth-perl installlibtext-iconv-perl installlibtext-wrapi18n-perl installlibtinfo5:amd64 installlibusb-0.1-4:amd64 installlibustr-1.0-1:amd64 installlibuuid1:amd64 installlogin installlsb-base installmawk installmount installmultiarch-support installncurses-base installncurses-bin installnetbase installpasswd installperl-base installreadline-common installsed installsensible-utils installsysv-rc installsysvinit installsysvinit-utils installtar installtzdata installutil-linux installxz-utils installzlib1g:amd64 install
Feedback
This is one of my first Docker images (see all of them here) so please give me feedback in the comments. Thanks!