Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trash PHP sources after build to reduce image size #886

Closed

Conversation

bdossantos
Copy link

@bdossantos bdossantos commented Sep 5, 2019

Hi there,

Since two minor versions I have the impression that the PHP image based on Debian has taken a little weight (~ 20MB wasted space) ...

I looked in the layers of the images with dive (https://github.com/wagoodman/dive) and noticed that PHP sources are no longer purged at the end of the build.

dive php:7.2.22-fpm-buster

Screen Shot 2019-09-05 at 11 04 16 AM

dive php:7.2.20-fpm-buster

Screen Shot 2019-09-05 at 11 08 12 AM

You will find a potential fix attached to this PR (on the other hand I have not yet been able to test it thoroughly).

Thank you.

@shouze
Copy link
Contributor

shouze commented Sep 5, 2019

So... what about

docker-php-source delete; \
🤔

@bdossantos
Copy link
Author

bdossantos commented Sep 5, 2019

https://github.com/docker-library/php/blob/master/docker-php-source#L4

dir=/usr/src/php and later rm -rf "$dir", /usr/src/php.tar.xz isn't deleted by the previous command, no wildcard.

A more appropriate fix could be dir=/usr/src/php*, dir=/usr/src/*, whatever if your prefer :-) ?

"Regression" is also visible there (I inherit from official image), since 7.2.19 https://hub.docker.com/r/bdossantos/php-lol/tags

@tianon
Copy link
Member

tianon commented Sep 5, 2019

I think #488 has some useful context and links here (and I'd even go so far as to say this is technically a duplicate of #488).

@yosifkit
Copy link
Member

yosifkit commented Sep 5, 2019

Closing as duplicate of #488. /usr/src/php.tar.xz is left in on purpose.

Also, I see no size difference in the two:

$ docker pull php:7.2.22-fpm-buster
7.2.22-fpm-buster: Pulling from library/php
1ab2bdfe9778: Pull complete 
1448c64389e0: Pull complete 
4b8a4e62b444: Pull complete 
9eb9d1e8e241: Pull complete 
1ea1192f8448: Pull complete 
ec5a150f7008: Pull complete 
f39d8e1e9c06: Pull complete 
ec9ce5c6ea3e: Pull complete 
dab566ec6646: Pull complete 
d978f8b39145: Pull complete 
4a364e7ada90: Pull complete 
Digest: sha256:43868cbbdb154b8984a563201bab31b0165f95a5816a47b5d6206ecd1aa27a84
Status: Downloaded newer image for php:7.2.22-fpm-buster
docker.io/library/php:7.2.22-fpm-buster
$ docker pull php:7.2.20-fpm-buster
7.2.20-fpm-buster: Pulling from library/php
f5d23c7fed46: Pull complete 
4f36b8588ea0: Pull complete 
6f4f95ddefa8: Pull complete 
187af28c9b1d: Pull complete 
e0725e1eb209: Pull complete 
304248ba6ef5: Pull complete 
1b794fb649f1: Pull complete 
10db73209341: Pull complete 
7e72f23fca95: Pull complete 
adb83d02e947: Pull complete 
8da286a4ed1e: Pull complete 
Digest: sha256:d989a4e0f16bde44d1fc2707336f2f8d68da1e016140d1b0efcad7d0acdfca97
Status: Downloaded newer image for php:7.2.20-fpm-buster
docker.io/library/php:7.2.20-fpm-buster
$ docker image ls php
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
php                 7.2.22-fpm-buster   8bbd5f15e775        2 days ago          400MB
php                 7.2.20-fpm-buster   624d2c6f6bdd        6 weeks ago         400MB

If you are talking about 7.2.19, I would assume the size difference is because it was only available on stretch (there was no buster based image):

$ docker image ls php
REPOSITORY          TAG                  IMAGE ID            CREATED             SIZE
php                 7.2.22-fpm-stretch   cb4074407379        2 days ago          367MB
php                 7.2.22-fpm-buster    8bbd5f15e775        2 days ago          400MB
php                 7.2.20-fpm-buster    624d2c6f6bdd        6 weeks ago         400MB
php                 7.2.20-fpm-stretch   f9738c3d4df5        7 weeks ago         366MB
php                 7.2.19-fpm           715ebd6c8c4d        2 months ago        371MB
php                 7.2.19-fpm-stretch   715ebd6c8c4d        2 months ago        371MB

@yosifkit yosifkit closed this Sep 5, 2019
bdossantos added a commit to bdossantos/dockerfiles that referenced this pull request Nov 15, 2019
bdossantos added a commit to bdossantos/dockerfiles that referenced this pull request Nov 15, 2019
@wglambert wglambert mentioned this pull request Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants