Why is my docker image size much bigger than my application?
I built my docker image as follows:
FROMa 3rd-party image on Docker Hub (~1GB)
apt-get installsome packages (~ 16MB)
COPYmy application binary into the image (~10MB)
If docker images/layers are like git commits, then it looks to me that the actual new data I have created shall be about 16+10=26MB, while everything else are existing stuffs and can be referenced.
docker save produces a tar over 1GB size, presumably because it wants to include everything and be self-contained.
What puzzles me is that
docker push (to Docker Hub) also seems to push existing image/layers in addition to the 26MB created by me.
I wonder why it is the case. I probably do not understand docker’s internal correctly and any pointer will be appreciated as well.
$ docker history foo/bar IMAGE CREATED CREATED BY SIZE COMMENT fd29a2b9e9a0 16 hours ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "java - 0 B a3362d2cf4b8 16 hours ago /bin/sh -c #(nop) WORKDIR /app 0 B 91526d6ec049 16 hours ago /bin/sh -c #(nop) COPY file:a43a96c41b91065fb 9.359 MB 95966578925f 16 hours ago /bin/sh -c apt-get update && apt-get install 15.87 MB ---- note: below are from 3rd-party image bd13d10574b7 19 hours ago /bin/sh -c #(nop) CMD ["scala"] 0 B ad53ab215b06 19 hours ago /bin/sh -c echo "==> Install curl helper tool 489.3 MB 08954c5f483e 19 hours ago /bin/sh -c #(nop) ENV SCALA_TARBALL=http://ww 0 B 0b56b2fe5cae 19 hours ago /bin/sh -c #(nop) ENV SCALA_VERSION=2.11.6 0 B e65c586f9327 19 hours ago /bin/sh -c #(nop) MAINTAINER William Yeh <wil 0 B 693e0795d114 19 hours ago /bin/sh -c #(nop) CMD ["java"] 0 B aef671641ab3 19 hours ago /bin/sh -c echo "===> add webupd8 repository. 391.4 MB 7a01cc5f27b1 9 days ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B dbacfa057b30 9 days ago /bin/sh -c #(nop) ADD file:e5a3d20748c5d3dd5f 125.1 MB $ docker push foo/bar The push refers to a repository [docker.io/foo/bar] (len: 1) fd29a2b9e9a0: Image successfully pushed a3362d2cf4b8: Image successfully pushed 91526d6ec049: Image successfully pushed 95966578925f: Image successfully pushed bd13d10574b7: Image already exists ad53ab215b06: Image successfully pushed -- why? 08954c5f483e: Image already exists 0b56b2fe5cae: Image already exists e65c586f9327: Image already exists 693e0795d114: Image already exists aef671641ab3: Image successfully pushed -- why? 7a01cc5f27b1: Image already exists dbacfa057b30: Image successfully pushed -- why? latest: digest: sha256:47b68552f75c274730d3c66f8e7ab95a1eb9fea3ef5e6b21aec24b4ebfd5e912 size: 23589