Moving cleanup to dramatically reduce image size
Description
Moving cleanup to the same RUN as install and build reduces image size. Right now the cleanup is a separate RUN command in the docker files. At the end of a RUN command a new layer is created. Doing cleanup in a later layer does nothing for the resulting docker image.
Steps to reproduce
- Build current docker image
- Move cleanup command (for example https://github.com/craftcms/docker/blob/main/8.2/Dockerfile#L116) to the same step where the installs are performed.
- Optionally move MozJPEG to a separate build stage
- Build image again to compare to previous one
Additional info
-
craftcms/cmsversion: - - PHP version: -
- Database driver & version: -
- Plugins & versions: -
@roelvanhintum Please see https://github.com/craftcms/docker/issues/93
@timkelty Thanks! Regardless of that, it would still be a huge improvement. Maybe this is also the case in the new images? We made our own version, based upon the images here but without imagick, resulting in 197MB vs craftcms/nginx:8.2 931MB
@roelvanhintum agreed! We're happy to accept a PR, or if we get the time before we officially read-only this repo, it seems worthwhile.
I'm going to leave this open for now.
Pinging @jasonmccallister to make any cleanup is happening in the appropriate layers in the new images.
@roelvanhintum @timkelty see #41