Size of docker images

I am just getting started with docker. Here are the images I have:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my-docker-image latest dba7dc0c4b67 37 minutes ago 274.6 MB
ubuntu latest cf62323fa025 7 days ago 125 MB
hello-world latest c54a2cc56cbb 2 weeks ago 1.848 kB
docker/whalesay latest 6b362a9f73eb 13 months ago 247 MB
my-docker-image2 latest 6b362a9f73eb 13 months ago 247 MB

The hello-world is just a few KB. I believe the image itself would be based on an existing image which makes it a full image. If that is so, the size should have run into MBs.

The whalesay image seems to be a full-sized image. I am told that docker manages images in layers and hence only the changes from the base layer are expected to go in an image. If the hello-world is small because it is a simple program, the whalesay should also have run into a few KBs or a couple of MBs. Why is that image so big?

It doesn’t have to be. Some images (especially those built around Go programs) consist of as little as a single statically-compiled binary. That’s probably the case here.

docker history can tell you.

The other thing to note in this space is that layers are shared. If my-docker-image is built from a Dockerfile that begins FROM docker/whalesay, then even though docker images reports that it requires 274.6 MB, it’s actually quite a small incremental difference, since it reuses the same layers from the base image. Similarly, if whalesay is built on that exact ubuntu image, then the total on-disk space requirements for this set of images might be less than 250 MB.

1 Like