Docker Tutorial
Docker Installation
How to use Docker
Docker Instance
Docker Container Lifecycle Command
Docker Container Operation Command
Docker Container rootfs Command
Docker Mirror Repository Command
Docker Local Image Management Command
Docker info|version Command
The docker history
command allows you to inspect the history and layers of a Docker image, providing insight into how the image was built and the changes that have been made. This tutorial will guide you through the basics of using the docker history
command.
Prerequisites:
docker pull ubuntu:20.04
This command will download the ubuntu:20.04
image from the Docker Hub.
Inspect the history of an image:
To display the history of an image, use the following syntax:
docker history IMAGE
Replace IMAGE
with the image ID or name.
For example, to inspect the history of the ubuntu:20.04
image, use:
docker history ubuntu:20.04
This will display a table with the following columns:
IMAGE
: The ID of the layer.CREATED
: The time the layer was created.CREATED BY
: The command that was used to create the layer.SIZE
: The size of the layer.COMMENT
: Any comments associated with the layer.Format the output:
By default, the docker history
command displays the image history in a table format. If you want to change the output format, you can use the --format
or -f
flag followed by a Go template string.
For example, to display the image history with a custom format, use:
docker history -f '{{.ID}}\t{{.CreatedBy}}\t{{.Size}}' IMAGE
Replace IMAGE
with the image ID or name.
This command will display the image history with the layer ID, command used to create the layer, and the size of the layer, separated by tabs.
Display image history with human-readable sizes:
By default, the SIZE
column displays the size in bytes. If you want to display the size in a more human-readable format, use the --human
or -H
flag:
docker history --human IMAGE
Replace IMAGE
with the image ID or name.
This command will display the image history with sizes in a human-readable format, such as "32MB" or "2GB".
In this tutorial, we covered the basics of using the docker history
command to inspect the history and layers of a Docker image. The docker history
command provides valuable insight into the build process and can help you understand the changes that have been made to an image over time. Additionally, by formatting the output and using the --human
flag, you can tailor the output to your specific needs.
How to Use Docker History Command:
docker history
command provides a detailed view of the layers that make up a Docker image, showing the commands executed in each layer during the image's creation.docker history <image_name>
Viewing Image Layers with Docker History:
docker history <image_name>
Analyzing Docker Image History:
docker history <image_name>
Docker History Command Options:
docker history
command supports various options for customizing the output, such as formatting, truncation, and filtering.docker history --format "{{.Size}}" <image_name>
Checking Changes in Docker Image History:
docker history <image_name> | grep -i "change"
Inspecting Docker Image Metadata with History:
docker history
command.docker history --format "{{.CreatedBy}} {{.Size}} {{.Comment}}" <image_name>
Filtering Docker Image History Output:
docker history
command allows you to filter the output based on specific criteria, such as commands or image sizes.docker history --filter "CMD" <image_name>
Docker History and Image Size Optimization:
docker history --format "{{.Size}}" <image_name> | awk '{total+=$1}END{print total}'
Analyzing Image Creation Steps with Docker History:
docker history --no-trunc <image_name>