mohsenasm / swarm-dashboard

A Simple Monitoring Dashboard for Docker Swarm Cluster
MIT License
162 stars 26 forks source link

Make the resulting image smaller #9

Closed charypar closed 7 years ago

charypar commented 7 years ago

Resolves #8.

The original docker image was relatively large for what it did. This reduces the size from 249 MB to 68.7 MB by using a multi-stage build, switching to Alpine Linux based Node 8 base image for runtime and removing Babel entirely (except for parsing in eslint).

Note that the Elm compilation stage still uses node:6-slim, as the npm installer fails on all other base images I tried (:6-alpine, :8-alpine, :8-slim). Not sure why... Fortunately, thanks to multi-stage builds and only using the compiled output, it doesn't matter.

Here are the image layers:

Original - node:6-slim - 294MB

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
e8851fcf3869        26 hours ago        /bin/sh -c #(nop)  CMD ["node" "server/ind...   0B
4f1bd2d6d7c5        26 hours ago        /bin/sh -c #(nop)  HEALTHCHECK &{["CMD-SHE...   0B
1eb607d09137        26 hours ago        /bin/sh -c elm make Main.elm --output=clie...   1.49MB
8ed83ef17599        26 hours ago        /bin/sh -c #(nop) COPY dir:12474853451b875...   5.04MB
15c219d8f8fd        26 hours ago        /bin/sh -c elm package install -y               976kB
6c7613599754        26 hours ago        /bin/sh -c yarn install --production            61.5MB
dba4a330e725        26 hours ago        /bin/sh -c #(nop) COPY multi:cb045d350348c...   69.6kB
f2e64b98f7d7        29 hours ago        /bin/sh -c #(nop)  ENV NODE_ENV=production      0B
6c5fb37cb0b3        29 hours ago        /bin/sh -c #(nop) WORKDIR /home/node/app        0B
25d92dc2959f        29 hours ago        /bin/sh -c npm install -g elm --silent > /...   38.6MB
e42b0ed3306c        4 days ago          /bin/sh -c #(nop)  CMD ["node"]                 0B
<missing>           4 days ago          /bin/sh -c set -ex   && for key in     6A0...   3.89MB
<missing>           4 days ago          /bin/sh -c #(nop)  ENV YARN_VERSION=0.27.5      0B
<missing>           4 days ago          /bin/sh -c buildDeps='xz-utils'     && ARC...   42.5MB
<missing>           12 days ago         /bin/sh -c #(nop)  ENV NODE_VERSION=6.11.2      0B
<missing>           2 weeks ago         /bin/sh -c #(nop)  ENV NPM_CONFIG_LOGLEVEL...   0B
<missing>           2 weeks ago         /bin/sh -c set -ex   && for key in     955...   131kB
<missing>           2 weeks ago         /bin/sh -c groupadd --gid 1000 node   && u...   335kB
<missing>           3 weeks ago         /bin/sh -c set -ex;  if ! command -v gpg >...   0B
<missing>           3 weeks ago         /bin/sh -c apt-get update && apt-get insta...   44.6MB
<missing>           3 weeks ago         /bin/sh -c #(nop)  CMD ["bash"]                 0B
<missing>           3 weeks ago         /bin/sh -c #(nop) ADD file:a023a99f7d01868...   123MB

node-8:alpine + multi-stage build - 82.6MB

IMAGE               CREATED              CREATED BY                                      SIZE                COMMENT
657dbb62df90        About a minute ago   /bin/sh -c #(nop)  CMD ["node" "server/ind...   0B
c3c2e7f11625        About a minute ago   /bin/sh -c #(nop)  HEALTHCHECK &{["CMD-SHE...   0B
ed2cbe7cc44d        About a minute ago   /bin/sh -c ls -la .                             0B
df442cc6d99c        About a minute ago   /bin/sh -c #(nop) COPY dir:90dbb6fee800a52...   1.87kB
15678b00bffc        About a minute ago   /bin/sh -c #(nop) COPY dir:fab059e67cb47bd...   329kB
1e5dcf896818        About a minute ago   /bin/sh -c #(nop) COPY dir:44e1e1463fb7c58...   15.1MB
44401121d71d        6 minutes ago        /bin/sh -c #(nop) WORKDIR /home/node/app        0B
0ef8c7adb1a2        About an hour ago    /bin/sh -c #(nop) WORKDIR /home/node/app        0B
3066c7645b22        About an hour ago    /bin/sh -c #(nop)  ENTRYPOINT ["/sbin/tini...   0B
a188ac2faa70        About an hour ago    /bin/sh -c apk add --update tini curl   &&...   1.41MB
100eefff29d9        4 days ago           /bin/sh -c #(nop)  CMD ["node"]                 0B
<missing>           4 days ago           /bin/sh -c apk add --no-cache --virtual .b...   3.92MB
<missing>           4 days ago           /bin/sh -c #(nop)  ENV YARN_VERSION=0.27.5      0B
<missing>           4 days ago           /bin/sh -c addgroup -g 1000 node     && ad...   57.9MB
<missing>           4 days ago           /bin/sh -c #(nop)  ENV NODE_VERSION=8.3.0       0B
<missing>           6 weeks ago          /bin/sh -c #(nop)  ENV NPM_CONFIG_LOGLEVEL...   0B
<missing>           6 weeks ago          /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B
<missing>           6 weeks ago          /bin/sh -c #(nop) ADD file:4583e12bf5caec4...   3.97MB

node-8:alpine + multi-stage build + no Babel - 68.7MB

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
b4ad96bb3a7a        2 minutes ago       /bin/sh -c #(nop)  CMD ["node" "server/ind...   0B                  
e39a642e8990        2 minutes ago       /bin/sh -c #(nop)  HEALTHCHECK &{["CMD-SHE...   0B                  
b5c9fed31fd3        2 minutes ago       /bin/sh -c #(nop) COPY dir:d20af176f88477f...   1.77kB              
da9be9818510        2 minutes ago       /bin/sh -c #(nop) COPY dir:fab059e67cb47bd...   329kB               
6047098c82af        2 minutes ago       /bin/sh -c #(nop) COPY dir:06c0ec60d6f5847...   1.19MB              
44401121d71d        About an hour ago   /bin/sh -c #(nop) WORKDIR /home/node/app        0B                  
0ef8c7adb1a2        2 hours ago         /bin/sh -c #(nop) WORKDIR /home/node/app        0B                  
3066c7645b22        2 hours ago         /bin/sh -c #(nop)  ENTRYPOINT ["/sbin/tini...   0B                  
a188ac2faa70        2 hours ago         /bin/sh -c apk add --update tini curl   &&...   1.41MB              
100eefff29d9        4 days ago          /bin/sh -c #(nop)  CMD ["node"]                 0B                  
<missing>           4 days ago          /bin/sh -c apk add --no-cache --virtual .b...   3.92MB              
<missing>           4 days ago          /bin/sh -c #(nop)  ENV YARN_VERSION=0.27.5      0B                  
<missing>           4 days ago          /bin/sh -c addgroup -g 1000 node     && ad...   57.9MB              
<missing>           4 days ago          /bin/sh -c #(nop)  ENV NODE_VERSION=8.3.0       0B                  
<missing>           6 weeks ago         /bin/sh -c #(nop)  ENV NPM_CONFIG_LOGLEVEL...   0B                  
<missing>           6 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B                  
<missing>           6 weeks ago         /bin/sh -c #(nop) ADD file:4583e12bf5caec4...   3.97MB    
charypar commented 7 years ago

It looks like Docker Hub doesn't support multi-stage builds just yet :( https://hub.docker.com/r/charypar/swarm-dashboard/builds/b6ql9kh27r7as8yexpmdnxd/

charypar commented 7 years ago

Here's an issue tracking it https://github.com/docker/hub-feedback/issues/1039, the gist is Docker Hub runs Docker EE, which doesn't have a 17.06 release yet.

charypar commented 7 years ago

Well, Docker Cloud works :)