<p>You shouldn't need to statically link things to remove the <code>*-dev</code> packages and have everything still work. If you do, then that's a bug in the base package and the <code>-dev</code> 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:</p>

<pre class="lang-sh prettyprint-override"><code>apt-get install -y libghc-postgresql-simple &amp;&amp; apt-get remove libghc-postgresql-simple-dev
</code></pre>

<hr>

<p>There are two other things you can do to improve your image sizes:</p>

<ul>
<li>Use the <code>--no-install-recommends</code> switch for all of your <code>apt-get install</code> 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 <em>lot</em> 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.</li>
<li>Use the <code>--purge</code> 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.</li>
</ul>

CC BY-SA 4.0
2020-02-14T15:48:07.700Z
2020-02-14T15:48:07.700Z
Austin Hemmelgarn
<p>Usually when I build docker images for php I use this approach:</p>

<pre><code>FROM  php:7.2-apache

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

<p>But this can result an image of 1.2GB and I need to shave some space. AFAIK header files such as the <code>libghc-postgresql-simple-dev</code> 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 <code>libghc-postgresql-simple</code> or removing it completely.</p>

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

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

<docker><dockerfile><php>
Do I need header files once I install the php extention on Dockerfile?
Dimitrios Desyllas
# Do I need header files once I install the php extention on Dockerfile?

(Asked by: username_0 on 2020-02-13)

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.

**Tags:** docker, dockerfile, php


---

## 1 answers

### Answer by username_1 on 2020-02-14. Score: 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.


---

