Sometimes when building Docker images it's necessary to use apt-get
. For example, an image for running Magento might start something like this
FROM php:5.4-apache
RUN apt-get -qqy update \
&& apt-get -qqy install git \
libmcrypt-dev \
libpng12-dev \
libxml2-dev \
libxslt-dev \
&& docker-php-ext-install bcmath \
gd \
mcrypt \
mysql \
soap \
xsl \
zip
But now I have all the junk brought in by those apt-get
commands. Worse, I'm not even sure what I can afford to delete, because presumably the php libs are dynamically linked.
I'm thinking along lines such as
- Is there a way to statically link the php libs in
docker-php-ext-install
so I can nuke all theapt-get
stuff? - How can I remove the data left by
apt-get update
?
but those are really just X-Y questions. My actual question is just
How can I build smaller Docker images without entirely trading away the ease-of-use and maintainability of using apt-get
in the Dockerfile?