Docker history命令

本文将介绍Docker的history命令,history命令用来显示镜像创建的历史记录信息。

docker history命令用来显示镜像创建的历史记录信息。帮助信息如下:

[root@localhost ~]# docker history --help

Usage:  docker history [OPTIONS] IMAGE

Show the history of an image

Options:
      --format string   Pretty-print images using a Go template
  -H, --human           Print sizes and dates in human readable format (default true)
      --no-trunc        Don't truncate output
  -q, --quiet           Only show numeric IDs

其中:

  • --format string  使用Go模板打印漂亮的图像列表

  • -H, --human    以人类可读格式打印大小和日期(默认为true)

  • --no-trunc      不截断输出

  • -q, --quiet      只显示数字ID

实例1:查看ubuntu镜像的历史信息。如下:

[root@localhost ~]# docker history ubuntu
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
4c108a37151f        4 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B
<missing>           4 weeks ago         /bin/sh -c mkdir -p /run/systemd && echo 'do…   7B
<missing>           4 weeks ago         /bin/sh -c set -xe   && echo '#!/bin/sh' > /…   745B
<missing>           4 weeks ago         /bin/sh -c [ -z "$(apt-get indextargets)" ]     987kB
<missing>           4 weeks ago         /bin/sh -c #(nop) ADD file:4e6b5d9ca371eb881…   63.2MB

实例2:查看指定tag的镜像历史信息。如下:

[root@localhost ~]# docker history centos:6.7
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
9f1de3c6ad53        4 months ago        /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B
<missing>           4 months ago        /bin/sh -c #(nop)  LABEL License=GPLv2          0B
<missing>           4 months ago        /bin/sh -c #(nop)  LABEL Vendor=CentOS          0B
<missing>           4 months ago        /bin/sh -c #(nop) ADD file:c6a7eec8d88e4caed…   191MB
<missing>           9 months ago        /bin/sh -c #(nop)  MAINTAINER The CentOS Pro…   0B

实例3:查看我们自己构建镜像的历史信息。Dockerfile如下:

# 继承基础镜像centos:latest
FROM centos
# 设置作者信息
MAINTAINER myName<myName@163.com>

# 定义环境变量
ENV mypath /tmp
WORKDIR $mypath

# 安装 vim 和 ifconfig
RUN yum -y install vim
RUN yum -y install net-tools

# 暴露80端口
EXPOSE 80
CMD echo $mypath
CMD echo "success-------------------------ok"
CMD /bin/bash

使用“docker build myimage:v1.0 .”命令根据Dockerfile构建镜像。然后使用“docker history myimage:v1.0”命令查看镜像历史信息,如下:

[root@localhost ~]# docker history myimage:v1.0
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
729e175d50db        18 minutes ago      /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "/bin…   0B
a5a1d43de63e        18 minutes ago      /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "echo…   0B
1bebe4e64a58        18 minutes ago      /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "echo…   0B
b1f8be9fbfab        18 minutes ago      /bin/sh -c #(nop)  EXPOSE 80                    0B
9056bf940f16        18 minutes ago      /bin/sh -c yum -y install net-tools             105MB
f3763706802c        18 minutes ago      /bin/sh -c yum -y install vim                   160MB
f5e34ba2d527        18 minutes ago      /bin/sh -c #(nop) WORKDIR /tmp                  0B
15592795a5c9        18 minutes ago      /bin/sh -c #(nop)  ENV mypath=/tmp              0B
95489bc8a299        18 minutes ago      /bin/sh -c #(nop)  MAINTAINER myName<myName@…   0B
9f38484d220f        4 months ago        /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B
<missing>           4 months ago        /bin/sh -c #(nop)  LABEL org.label-schema.sc…   0B
<missing>           4 months ago        /bin/sh -c #(nop) ADD file:074f2c974463ab38c…   202MB

仔细将历史信息和Dockerfile文件进行比对,返现就是我们Dockerfile中的每一条命令。上面的每一行代表的镜像的一层,镜像就是一个“花卷”,一层层组成的。

学习知识要善于思考,思考,再思。我就是靠这个方法成为科学家的。 —— 爱因斯坦
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号