Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze and explore the contents of Docker container images

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to analyze and explore the contents of Docker container images". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to analyze and explore the contents of Docker container images.

You may have learned that the Docker container image is a lightweight, stand-alone executable package that contains all the software needed to run an application, which is why the container image is often used by developers to build and distribute applications. If you are curious about what is contained in a Docker image, this brief guide may help you. Today, we will learn to use a tool called Dive to analyze and explore the content of each layer of Docker images.

By analyzing the Docker image, we can find files that may duplicate between layers and reduce the size of the Docker image by removing them. The Dive tool is not just a Docker image analysis tool, it can also help us build images. Dive is a free open source tool written in the Go programming language.

Install Dive

First download the * * version from the release page of the project, and then install it according to the distribution you are using, as shown below.

If you are using Debian or Ubuntu, you can run the following command to download and install it.

$wget https://github.com/wagoodman/dive/releases/download/v0.0.8/dive_0.0.8_linux_amd64.deb$ sudo apt install. / dive_0.0.8_linux_amd64.deb

In RHEL or CentOS systems

$wget https://github.com/wagoodman/dive/releases/download/v0.0.8/dive_0.0.8_linux_amd64.rpm$ sudo rpm-I dive_0.0.8_linux_amd64.rpm

Dive can also be installed using the Linuxbrew package manager.

$brew tap wagoodman/dive$ brew install dive

For other installation methods, please refer to the GitHub page of the Dive project.

Analyze and explore the contents of Docker images

To analyze a Docker image, simply run the dive command with the Docker image ID. You can use sudo docker images to get the ID of the Docker image.

$sudo dive ea4c82dcd15a

The ea4c82dcd15a in the above command is the ID of a mirror.

The dive command will then quickly analyze the contents of the given Docker image and display it in the terminal.

As you can see in the screenshot above, the left column of the terminal lists the layers of a given Docker image and their details, the amount of space wasted, and so on. The column on the right shows the contents of each layer of a given Docker image. You can use the Ctrl+ space to switch between the left and right columns, and use the UP/DOWN cursor key to browse through the directory tree.

Here is a list of shortcut keys for dive:

Ctrl+ spaces-switch between left and right columns

Spaces-expand or fold the directory tree

Ctrl+A-File Tree View: show or hide added files

Ctrl+R-File Tree View: shows or hides removed files

Ctrl+M-File Tree View: show or hide modified files

Ctrl+U-File Tree View: show or hide unmodified files

Ctrl+L-layer view: shows the changes in the current layer

Ctrl+A-layer view: show the overall changes

Ctrl+/-filter files

Ctrl+C-exit

In the above example, I used the sudo permission because my Docker image is stored in the / var/lib/docker/ directory. If your image is saved in your home directory ($HOME) or in another directory that does not belong to root users, you do not need to use the sudo command.

You can also use the following single command to build a Docker image and analyze it immediately:

$dive build-t

The Dive tool is still in the beta phase, so bug may exist. If you encounter bug, please report on the project's GitHub home page.

At this point, I believe you have a deeper understanding of "how to analyze and explore the contents of Docker container images". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report