YouTip LogoYouTip

Docker History Command

[![Image 1: Docker Command Manual](#)Docker Command Manual](#) * * * The `docker history` command is used to view the history layer information of a specified image. It displays each layer in the image creation process, including creation time, creator, size, and comments. ### Syntax docker history IMAGE * **`IMAGE`**: The name or ID of the image to view the history for. OPTIONS Description: * **`-H, --human`**: Print sizes and dates in human-readable format (enabled by default). * **`--no-trunc`**: Show the full output, don't truncate information. * **`-q, --quiet`**: Only show image IDs. ## Examples **1. View Image History** docker history myimage:latest Output Example: 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 Full Output** docker history --no-trunc myimage:latest **3. Show Only Image IDs** docker history -q myimage:latest Output Example: sha256:123abc456def sha256:789ghi012jkl sha256:345mno678pqr sha256:678stu901vwx sha256:901yza234bcd ### Practical Example **Building a Simple Image** 1. Create a Dockerfile: # Use Ubuntu as the base image 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's default web directory COPY index.html /var/www/html/# Set the default command to run at startup CMD ["nginx", "-g", "daemon off;"] 2. Build the image: docker build -t mynginx:latest . 3. View the image history docker history mynginx:latest Output Example: 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 * The image history information includes the creation command and size for each layer, which helps in understanding the image's build process and content. * Using the `--no-trunc` option allows you to view the full creation commands, avoiding information truncation. * When building complex images, reviewing the history can help identify and optimize redundant steps in the Dockerfile. The `docker history` command is a powerful tool that helps developers and operations personnel understand the build history of an image and the details of each layer. By viewing the image history, you can better debug, optimize, and audit Docker images, ensuring their efficiency and security. * * Docker Command Manual](#)
← Docker Import CommandDocker Tag Command β†’