How to explore and optimize your Docker images with Dive

When you start to become interested in Docker, everything seems simple and light, at least on the surface. By the way, if you’re new to Docker, here is a guide on how to install Docker on Linux ex Ubuntu

But for a Docker image to be considered okay, it must be optimized, and it’s not necessarily instinctive, especially when you’re just starting out.

This is why I present to you a tool as magical as Fabien Olicard under Caprisun, which will not only allow you to understand the structure of your Docker images from top to bottom but also to optimize their size and free up this precious disk space that we all lack on our computers. This tool is Dive.

Imagine you are a developer or system administrator and regularly need to manipulate and manage Docker images. You know it’s crucial to optimize these images to reduce their size and thus improve their effectiveness, but you don’t know where to start. Dive is here to help you! With this tool, you will be able to easily analyze your Docker images, discover the modifications made within each layer, and optimize their size efficiently.

First, simply replace the command docker build with dive build to analyze the efficiency and wasted space of your Docker image.

dive <tag/id/digest of your image>

Dive supports multiple image sources and container engines (currently Docker and Podman). For installation, Dive is available for Ubuntu/Debian, RHEL/Centos, Arch Linux, Mac, and Windows.

To install it on macOS:

brew install dive

To install it on Linux (Ubuntu / Debian):

export DIVE_VERSION=$(curl -sL "https://api.github.com/repos/wagoodman/dive/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')

curl -OL https://github.com/wagoodman/dive/releases/download/v${DIVE_VERSION}/dive_${DIVE_VERSION}_linux_amd64.deb

sudo apt install ./dive_${DIVE_VERSION}_linux_amd64.deb

Integrating Dive into your CI (continuous integration) process is also possible using the environment variable CI=true. You can even configure rules in a file .dive-ci to automate certain checks and optimizations of your Docker images.

Navigating Dive is a breeze, thanks to keyboard shortcuts. You will be able to explore the layers of your Docker images, filter files, manage layer-specific settings, and customize the user interface by creating a configuration file.

To learn more about Dive and its features, I invite you to consult the official GitHub repository here. Here, you’ll find all the information you need to master this fantastic tool, plus examples and tips for optimizing your Docker images like a pro.

Mohamed SAKHRI
Mohamed SAKHRI

I'm the creator and editor-in-chief of Tech To Geek. Through this little blog, I share with you my passion for technology. I specialize in various operating systems such as Windows, Linux, macOS, and Android, focusing on providing practical and valuable guides.

Articles: 1306

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

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