This is my old custom Dockerfile, and I want to make it a lot slimmer:
FROM php:7.2-apache
RUN \
apt-get update \
&& apt-get -y --no-install-recommends install \
# composer dependencies
git unzip openssh-client \
# utils for scripts
sudo \
# for the 'zip' PHP extension
libghc-zlib-dev \
# for avoiding 'zip' PHP extension's "deprecated" warnings
libzip-dev \
# for 'soap' PHP extension
libxml2-dev \
# for 'gd' PHP extension
libpng-dev \
# cleanup cache
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
# installing composer
&& curl -sS https://getcomposer.org/installer | \
php -- --install-dir=/usr/local/bin --filename=composer \
# for parallel composer install
&& composer global require hirak/prestissimo --no-plugins --no-scripts \
# PHP extensions special settings
# (to avoid "deprecated" warnings)
&& docker-php-ext-configure zip --with-libzip \
# install PHP extensions
&& docker-php-ext-install \
# mysql
pdo_mysql mysqli \
# zip, needed for xlsx processing
zip \
# for soap APIs
soap bcmath \
# for phpoffice/phpspreadsheet
gd \
# for symfony/polyfill-iconv
intl \
# for caching
opcache
I checked the total image size after some points:
- 380M after php:7.2-apache
- 408M after git unzip openssh-client
- 408M after sudo
- 962M after libghc-zlib-dev -> this is plus 554M
- 962M after libzip-dev
- 1.1G after libxml2-dev -> this is plus 200M
- 1.1G after libpng-dev
- 1.11G TOTAL at the end
As I see these are taking up most of the space: libghc-zlib-dev, libxml2-dev.
- Is there any slimmer solution to this?
- Can I delete something that is needed only at build time?
- Can I replace these with something smaller?
- Do I really need a 500M package (libghc-zlib-dev) to read .xlsx files with phpoffice/phpspreadsheet?
EDIT:
I did some experimenting after @Jakumi's comments, and the result is that I removed libghc-zlib-dev and added zlib1g-dev and still everything seem to be working, while the image size dropped from 1.11G to 542M
Some useful links I found while experimenting:
- libzip-dev, zlib1g-dev for zip in php: https://github.com/docker-library/php/issues/748#issuecomment-480449743 and Docker image build with PHP zip extension shows "bundled libzip is deprecated" warning
- libxml2-dev for soap in php: Enable soap for php in docker container
- libpng-dev for gd in php: Installing GD in Docker