Explore the layers of a Docker image with dive

Akriotis Kyriakos
3 min readJul 27, 2022

--

With dive, an interactive console tool written in Golang, you can explore through the different layers of a docker image.

What are docker layers

Every docker image contains the information of what changed in comparison to its parent image. All images have a parent one, except those that derive from scratch, a special case of a complete empty image that is useful when building base images or striped images that contain only the binaries of the application.

Each layer now, is practically an image itself, because it contains the changes we, or its creator, made on the parent image. An image can consist from a single or multiple layers and you can keep as a general rule of thumb that every instruction or instruction set in the Dockerfile, will eventually result in an additional layer and in a single intermediate image, which will act as the parent for the next steps — exception is when we talk about multi-stage images that mainly only the previous stage image and the actual stage’s instructions are pushed like distinct layers.

Layers are useful to avoid repeating build steps or pushing down the line information that is irrelevant for the end product.

Installation

Installation is fairly simple and straight-forward. For Ubuntu/Debian distributions:

wget https://github.com/wagoodman/dive/releases/download/v0.9.2/dive_0.9.2_linux_amd64.debsudo apt install ./dive_0.9.2_linux_amd64.deb

and for macOS environments is performed via brew:

brew install dive

Usage

The tool consists from one screen divided in two vertical panes. On the left one you can scroll through the various layers of the image and on the right one you can explore the files in a tree format. Files that have been added, removed or altered in any way are indicated with different color in the tree.

On the left pane besides the interactive list of layers, we find an additional segment that is presenting us an additional metric that estimates the efficiency score of our image by taking into consideration duplicates or redundant files copied across layers.

Based on that efficiency score, we can integrated the analysis of the image in a CI/CD pipeline by setting the configuration value CI=true and get a pass or fail result during the build process.

The UI is configurable in a certain degree via a YAML file and in addition to docker, dive supports the podman engine as well.

You can find detailed information in the github repository of the project:

Kudos

I have zero affiliation with the dive tool and its creators whatsoever, it just came to my knowledge and I find it extremely useful in my everyday tasks. The tool is developed by Alex Goodman, and although is still in beta the quality and usability are fantastic. I strongly recommend you pay a visit to his github account, it is literally a GO-ldmine (pun intended!)

--

--

Akriotis Kyriakos
Akriotis Kyriakos

Written by Akriotis Kyriakos

talking about: kubernetes, golang, open telekom cloud, aws, openstack, sustainability, software carbon emissions

No responses yet