Show Layers of Docker Image

Every speaking opportunity is a learning lesson, and hence a new opportunity to share. This blog will address one of the questions that has been bothering me for the past few days. It is about how to show different layers of Docker image, and their sizes, after it is downloaded.

Docker Logo

I was invited to talk about Docker for Java developers at Peru JUG this morning. The recording is now available:

The real content starts from 5:27.

Lets address the question now.

Each Docker image consists of a series of layers. Here is a quote from docs.docker.com:

Each image consists of a series of layers. Docker makes use of union file systems to combine these layers into a single image. Union file systems allow files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single coherent file system.

The exact size of the image can be easily seen using docker images:

The command to show different layers, and their size, is docker history:

This command shows different layers, command used for each layer, and the exact size of each image.

The corresponding Dockerfile for this image is at github.com/couchbase/docker/blob/master/enterprise/couchbase-server/4.0.0/Dockerfile.

Now I can compare the Dockerfile with the exact size and easily find which image layers are the biggest. For example, biggest contributors in this Couchbase image are shown below:

--no-trunc can be specified as an additional CLI option to history to show the complete command executed to build the layer.

As always, the latest slides are available at github.com/javaee-samples/docker-java/tree/master/slides.

Be Sociable, Share!

3 thoughts on “Show Layers of Docker Image

  1. Great article. I would also suggest checking out Imagelayers.io from Century Link. It is a graphical representation of the layers and you can actually compare the layers side-by-side. I use this quite often to visualize what’s changed with upgrades.

Leave a Reply

Your email address will not be published. Required fields are marked *