Closed ghost closed 7 years ago
You're quite right. But I just ran some tests, and the total image size isn't affected by this RUN command. It does however add another layer. So we could either remove the line altogether since it doesn't impact image size in a positive way either, or append it to the previous RUN statement. The total image size has increased with 8MB, but phpipam 1.3 is already 2.5MB larger than 1.2 and it does require some additional dependencies. So other than reducing the number of layers I don't see how we can reduce the overall size of the image unfortunately.
I have different results when testing here:
$ git remote add dotdev https://github.com/dotdev/phpipam && git fetch dotdev
$ docker build -t . dotdev/phpipam
(...)
$ docker images | grep dotdev/phpipam
dotdev/phpipam latest 25c70597e569 About a minute ago 445MB
$ docker rmi dotdev/phpipam
$ patch -p1 < my.patch
patching file Dockerfile
$ docker build -t . dotdev/phpipam:patched
(...)
$ docker images | grep dotdev/phpipam
dotdev/phpipam patched b5e4e33d9ba2 3 seconds ago 433MB
It's not only a matter of size, but also the fact that it removes one layer (size is the consequence, by directly cleaning up after installing apt packages). To me it's important to reduce the number of layers (especially since php:5.6 use them a bit too much...).
Here is my patch:
$ cat my.patch
diff --git a/Dockerfile b/Dockerfile
index 9baa2b7..ebc38e3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -7,7 +7,8 @@ ENV WEB_REPO /var/www/html
# Install required deb packages
RUN apt-get update && apt-get -y upgrade && \
- apt-get install -y php-pear php5-curl php5-mysql php5-json php5-gmp php5-mcrypt php5-ldap php5-gd php-net-socket libgmp-dev libmcrypt-dev libpng12-dev
+ apt-get install -y php-pear php5-curl php5-mysql php5-json php5-gmp php5-mcrypt php5-ldap php5-gd php-net-socket libgmp-dev libmcrypt-dev libpng12-dev && \
+ rm -rf /var/lib/apt/lists/*
# Configure apache and required PHP modules
RUN docker-php-ext-configure mysqli --with-mysqli=mysqlnd && \
@@ -23,9 +24,6 @@ RUN docker-php-ext-configure mysqli --with-mysqli=mysqlnd && \
echo ". /etc/environment" >> /etc/apache2/envvars && \
a2enmod rewrite
-RUN apt-get purge -y libgmp-dev libmcrypt-dev libpng12-dev && \
- rm -rf /var/lib/apt/lists/*
-
COPY php.ini /usr/local/etc/php/
# copy phpipam sources to web dir
I can merge your patch and then apply these optimizations on top if you want. Or do it directly. Please tell me.
Strange, but I'm still getting different results on the image size, but you patch is an improvement on both image size and layer count. Seems like the way to go, so please merge however you see fit. Whichever way is more convenient for you.