1

Usually when I build docker images for php I use this approach:

FROM  php:7.2-apache

RUN apt-get update && \
    apt-get install -y libghc-postgresql-simple-dev &&\
    docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql &&\
    docker-php-ext-install pdo pgsql pdo_pgsql &&\
    // Install some other extentions there
    apt-get autoremove -y &&\
    apt-get autoclean &&\
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* cache/* /var/lib/log/*

But this can result an image of 1.2GB and I need to shave some space. AFAIK header files such as the libghc-postgresql-simple-dev take a lot of space in my image so after building and installing the module I though of removing it and use the non-dev variant libghc-postgresql-simple or removing it completely.

So I want to ask: 1. Instead of dynamically linking it how I can statically link it on my build once i run docker-php-ext-install in order to remove the libghc-postgresql-simple-dev package? 2. Would once I build the php module removing the libghc-postgresql-simple-dev and using the libghc-postgresql-simple would make the php psql extention to work as supposed to?

The idea behind it is to optimize the build in order to make my image as small as possible.

1 Answer 1

1

You shouldn't need to statically link things to remove the *-dev packages and have everything still work. If you do, then that's a bug in the base package and the -dev package and should be reported upstream. So yes, you should in theory be able to, after installing your extensions and such, do the following and shrink the image significantly:

apt-get install -y libghc-postgresql-simple && apt-get remove libghc-postgresql-simple-dev

There are two other things you can do to improve your image sizes:

  • Use the --no-install-recommends switch for all of your apt-get install invocations, and explicitly list every package you depend on. Recommended dependencies are a type of optional dependency in Debian packages that are installed by default. They can often take up a lot of space, but you may not actually need most (or any) of them, so you can save space by not auto-installing them and only pulling in what you actually need. This can easily cut down image sizes multiple hundreds of MB.
  • Use the --purge option whenever removing packages. This will ensure that they leave nothing behind, instead of potentially leaving some config files and other similar stuff, which can also help cut down on your space usage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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