Do I need header files once I install the php extention on Dockerfile?
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 &amp;&amp; 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.