-
Task
-
Resolution: Done
-
Low
-
None
When I look into sdc image history with "docker history" command,
I see war file is stored in the image inefficiently:
$ docker history onap/sdc-backend IMAGE CREATED CREATED BY SIZE 35b2beae98f5 3 weeks ago /bin/sh -c #(nop) ENTRYPOINT ["/root/startu… 0B 4e73631e5e31 3 weeks ago /bin/sh -c chmod 770 /root/startup.sh 480B 3b4c7387a5ac 3 weeks ago /bin/sh -c #(nop) COPY file:4281ba554c6ae5e2… 480B 1616af02aeea 3 weeks ago /bin/sh -c chown -R jetty:jetty ${JETTY_BA… 119MB e16cf0a884f9 3 weeks ago /bin/sh -c #(nop) USER root 0B f249f16173ed 3 weeks ago /bin/sh -c #(nop) ADD file:110e7a4d294a5b88d… 119MB 5840b3a6e725 3 weeks ago /bin/sh -c #(nop) COPY dir:52b93daa2d43095f3… 153kB d6049e953b10 7 weeks ago /bin/sh -c #(nop) COPY dir:05e5e5d8c70532e16… 19.8kB f73ca120a361 7 months ago /bin/sh -c #(nop) USER jetty 0B
here, ADD .war file takes 119MB and chown takes another 119MB.
execution of chown for war file makes another layer in docker image and cause increasing the image size.
recent docker supports ADD/COPY commands with "--chown" flag which enables copying and chowning at the same time
so I propose a change to use that flag instead of executing chown to reduce sdc image size somewhat.
here is an example:
diff --git a/catalog-be/sdc-backend/Dockerfile b/catalog-be/sdc-backend/Dockerfile index 7fd9789..fc0c9cf 100644 --- a/catalog-be/sdc-backend/Dockerfile +++ b/catalog-be/sdc-backend/Dockerfile @@ -4,12 +4,10 @@ COPY chef-solo /root/chef-solo/ COPY chef-repo/cookbooks/. /root/chef-solo/cookbooks/ -ADD catalog-be-*.war ${JETTY_BASE}/webapps/ +ADD --chown=jetty:jetty catalog-be-*.war ${JETTY_BASE}/webapps/ USER root -RUN chown -R jetty:jetty ${JETTY_BASE}/webapps - COPY startup.sh /root/ RUN chmod 770 /root/startup.sh
I tested in my local env and I could reduce 220MB in total.
I think this change can also shorten download time a little.
onap/sdc-backend latest d15fca3db2ca 2 minutes ago 483MB nexus3.onap.org:10001/onap/sdc-backend 1.5-STAGING-latest 8b21f253a377 4 days ago 602MB onap/sdc-frontend latest 0d754fd04904 2 minutes ago 402MB nexus3.onap.org:10001/onap/sdc-frontend 1.5-STAGING-latest dd8208b4331d 4 days ago 440MB onap/sdc-onboard-backend latest a0ca9b9dca3d 2 minutes ago 427MB nexus3.onap.org:10001/onap/sdc-onboard-backend 1.5-STAGING-latest cf0f2dfd4633 4 days ago 490MB