Docker images are mostly HUGE, and I'm dreaming of a tiny, really tiny image of nginx.

The idea is to compile it and create a Docker image with only the nginx binary, config files, the required shared libraries, etc.

So the question is: how to figure out which shared libraries a compiled application will need?

Knowing the list, I would try make a folder with all the dependencies bundled, and ship it as the smallest Docker container.

It's not only about nginx, but rather a generic recipe on how to handle these cases. Maybe, some cross-compilation tecnhiques can help here?


So the question is: how to figure out which shared libraries a compiled application will need?

ldd is the tool you're looking for. For instance, here are the libraries nginx-1.1.19 on Ubuntu 12.04 LTS links to:

$ which nginx
$ ldd /usr/sbin/nginx
    linux-vdso.so.1 =>  (0x00007fff8fe50000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f02ecdfb000)
    libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f02ecbc2000)
    libpam.so.0 => /lib/x86_64-linux-gnu/libpam.so.0 (0x00007f02ec9b3000)
    libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f02ec789000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f02ec54c000)
    libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f02ec2ed000)
    libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f02ebf12000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f02ebcfb000)
    libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f02eb99e000)
    libxslt.so.1 => /usr/lib/x86_64-linux-gnu/libxslt.so.1 (0x00007f02eb762000)
    libexslt.so.0 => /usr/lib/x86_64-linux-gnu/libexslt.so.0 (0x00007f02eb54d000)
    libgd.so.2 => /usr/lib/x86_64-linux-gnu/libgd.so.2 (0x00007f02eb306000)
    libGeoIP.so.1 => /usr/lib/libGeoIP.so.1 (0x00007f02eb0d1000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f02ead12000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f02ed020000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f02eab0d000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f02ea811000)
    libgcrypt.so.11 => /lib/x86_64-linux-gnu/libgcrypt.so.11 (0x00007f02ea591000)
    libXpm.so.4 => /usr/lib/x86_64-linux-gnu/libXpm.so.4 (0x00007f02ea380000)
    libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f02ea130000)
    libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f02e9ef9000)
    libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f02e9c5d000)
    libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f02e9a35000)
    libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f02e9830000)
    libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f02e94fb000)
    libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f02e92dc000)
    libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f02e90d9000)
    libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f02e8ed3000)

In regard to whether or not this is a tenable means to make a stripped-down docker container is yet up in the air. I suspect there are many more bits you'll need to consider before you'll get this working.


An nginx container is heavy because it derives from a base OS install, and over it, it have installed nginx and all the required dependences and modules. But that base OS may be shared with other containers, making the "waste" less evident each time as you grow your use of containers.

Also maintaining the build recipe (i.e. when you need more modules, or security updates that may change dependences) could be easier with a simple Dockerfile that uses a base OS image and install the nginx package from the repositories than picking bit by bit what you need.

Anyway, if you want to build your own (tiny) base OS image, you have instructions in https://docs.docker.com/articles/baseimages/ along with suggestions for existing minimal ones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.