几个月来我一直在非常密集地使用 Docker,但我还没有经常使用 docker history
命令。
但是,我使用它的少数几次使我产生了一个假设,即有大量的“依赖图像”与我的“顶级”图像相关联,而不是 <强>层。
现在我明白了,上面的大部分假设都是基于这样一个事实,即很久以前,当我发出 docker history
命令时,最左边一列的标题是 IMAGE,而实际上,这些行实际上列出了与单个图像相关联的层,而不是图像。
这是一个示例 docker history
命令的屏幕截图:
Docker 中的 图像 和 层 之间存在关键区别,这就是为什么这确实是一个严肃的问题。
坦率地说,我对这个问题感到非常惊讶。如此重要的事情怎么会被 Docker 泄露出去?
我刚刚花了一段时间四处寻找有关此问题的讨论或答案。令人惊讶的是,即使是 Docker 'history' command documentation没有提到这一点。我见过的唯一真正的“确认”来自this link .
谁能告诉我为什么 docker history
中的列标题是“IMAGE”,而条目本身是层?
最佳答案
这很复杂 ;) This post by Nigel Brown super 对理解这一点很有用,但我将在此处提取相关要点。
Historically (pre Docker v1.10), each time a new layer was created as a result of a commit action, Docker also created a corresponding image, which was identified by a randomly generated 256-bit UUID, usually referred to as an image ID (presented in the UI as either a short 12-digit hex string, or a long 64-digit hex string).
所以,从历史上看,它们是图像,只是没有“人类友好”标签的中间图像(尽管它们可以被标记)。
Since Docker v1.10, generally, images and layers are no longer synonymous. Instead, an image directly references one or more layers that eventually contribute to a derived container's filesystem.
如果您执行 docker history
在拉取的图像上,您会看到类似的内容(摘自文章):
$ docker history swarm
IMAGE CREATED CREATED BY
SIZE COMMENT
c54bba046158 9 days ago /bin/sh -c #(nop) CMD ["--help"] 0 B
<missing> 9 days ago /bin/sh -c #(nop) ENTRYPOINT &{["/swarm"]} 0 B
<missing> 9 days ago /bin/sh -c #(nop) VOLUME [/.swarm] 0 B
<missing> 9 days ago /bin/sh -c #(nop) EXPOSE 2375/tcp 0 B
<missing> 9 days ago /bin/sh -c #(nop) ENV SWARM_HOST=:2375 0 B
<missing> 9 days ago /bin/sh -c #(nop) COPY dir:b76b2255a3b423981a 0 B
<missing> 9 days ago /bin/sh -c #(nop) COPY file:5acf949e76228329d 277.2 kB
<missing> 9 days ago /bin/sh -c #(nop) COPY file:a2157cec2320f541a 19.06 MB
您将看到 IMAGE
栏目报告 <missing>
,这些不是图像,而是作为图像组成部分的层。
所以它们不是图像!到底是什么,为什么这个列被命名? (回到你原来的问题)。好吧,除了……:
However, when a layer is committed during an image build on a local Docker host, an 'intermediate' image is created at the same time. Just like all other images, it has a configuration item which is a list of the layer digests that are to be incorporated as part of the image, and its ID or digest contains a hash of the configuration object. Intermediate images aren't tagged with a name, but, they do have a 'Parent' key, which contains the ID of the parent image.
所以实际上,当您构建 本地 时,这些组成层 是 图像(就像它们过去一样,即使您从其他地方拉取它们,直到 v1. 10),并用于促进构建缓存(如果您已经构建了该层,则可以加快构建速度)。
所以答案是......有时它们是图像(技术上),有时它们是层(然后在该列中表示为 <missing>
)。我猜它被保留为 IMAGE
出于 a) 历史原因和 b) 因为当某物出现在那里时它们实际上是图像,否则它只显示 <missing>
.我可以看出它们可能有点令人困惑,而且我在这里肯定可能会掩盖其他技术细节,但希望对您有所帮助!
免责声明:我为 Docker 工作,但我的观点/帖子是我自己的,等等......
关于docker - “docker 历史”命令 : Why does the column label say 'IMAGE' when the column contains layers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49710937/