Details
-
Story
-
Status: Closed
-
Medium
-
Resolution: Done
-
None
-
Policy 08/06/22-22/06/22, Policy 2022-06-30->2022-07-13, Policy 2022-07-13->2022-07-27
Description
Some of the Policy Framework docker images are much larger than needed.
As an example, by some simple changes, e.g. avoiding duplicate copies of files and avoiding running `chown` as a separate command where possible (docker's COPY and ADD command can take a chown parameter), the image size for policy-api was reduced from 956MB to 259MB (73% reduction). Based on analyzing the layers, this appears to be the smallest possible.
There are a few causes including:
- For some images, maven copies all jar dependencies into a tarball. Following Spring Boot migration, spring-boot-maven-plugin creates executable jars already containing all dependencies - thus data is being duplicated.
- Many images copy files into the image by creating a tarball, which creates 3 layers in the image: copying the tarball to the image (1st layer), extracting the archive and deleting the tarball (2nd layer), chown'ing the extracted files (3rd layer). This can be avoided e.g. by using multi-stage docker build.