Why is my docker image size much bigger than my application?

I built my docker image as follows:

  • FROM a 3rd-party image on Docker Hub (~1GB)
  • apt-get install some packages (~ 16MB)
  • COPY my 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 and NodeJS permission denied
  • Pass commands from one docker container to another
  • Docker port mapping
  • sh script unable to get executed in New Empty Docker Container
  • Docker container only accessible by another
  • docker on Azure VM windows 10
  • However, 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

  • Docker container restarting on defining an entrypoint
  • What does |1 mean in Docker history
  • Docker container stdout, stderr is being truncated. Is there a way to stop this?
  • Crypt32.dll not found for awssdk in .net core running in docker
  • Docker - AWS - What do I need to do next?
  • Running Python Script in Background Infinitely
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.