Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

The Docker history command

The Docker history command

Docker Command ReferenceDocker Command Reference


docker history This command views the historical layer information of a specified image. It shows each layer in the image creation process, including creation time, creator, size, and comments.

Syntax

docker history [OPTIONS] IMAGE

OPTIONS description:

Example

1. View image history



docker history myimage:latest

Example output:



IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

sha256:123abc456def 2 days ago          /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B

sha256:789ghi012jkl 2 days ago          /bin/sh -c #(nop)  COPY file:abc123 in /var/…   1.5kB

sha256:345mno678pqr 2 days ago          /bin/sh -c apt-get update && apt-get install…   45.3MB

sha256:678stu901vwx 2 days ago          /bin/sh -c #(nop)  LABEL maintainer=yourname…   0B

sha256:901yza234bcd 2 days ago          /bin/sh -c #(nop)  FROM ubuntu:20.04           72.9MB

2. Show the full output



docker history --no-trunc myimage:latest

3. Show only image IDs



docker history -q myimage:latest

Example output:



sha256:123abc456def

sha256:789ghi012jkl

sha256:345mno678pqr

sha256:678stu901vwx

sha256:901yza234bcd

Practical examples

Build a simple image

1. Create a Dockerfile:

# 使用 Ubuntu 作为基础镜像

FROM ubuntu:20.04



# Add maintainer information

LABEL maintainer="yourname@example.com"



# Update package list and install Nginx

RUN apt-get update && apt-get install -y nginx



# Copy custom webpage to Nginx default webpage directory

COPY index.html /var/www/html/



# Set the default command on startup

CMD ["nginx", "-g", "daemon off;"]

2. Build the image:



docker build -t mynginx:latest .

3. View the image history



docker history mynginx:latest

Example output:

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

sha256:123abc456def 1 minute ago        /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B

sha256:789ghi012jkl 1 minute ago        /bin/sh -c #(nop)  COPY file:abc123 in /var/…   1.5kB

sha256:345mno678pqr 1 minute ago        /bin/sh -c apt-get update && apt-get install…   45.3MB

sha256:678stu901vwx 1 minute ago        /bin/sh -c #(nop)  LABEL maintainer=yourname…   0B

sha256:901yza234bcd 1 minute ago        /bin/sh -c #(nop)  FROM ubuntu:20.04

Notes

docker history This command is a powerful tool that helps developers and operations personnel understand an image's build history and the detailed information of each layer. By viewing image history, you can better debug, optimize, and audit Docker images, ensuring their efficiency and security.


Docker Command ReferenceDocker Command Reference