拉取 Docker 个镜像时显示的 ID 是什么意思?

What is the meaning of the IDs shown when a Docker image is pulled?

从 DockerHub 拉取 Docker 图像时,CLI 会显示一些进度条,每个进度条都有不同的 ID:

➜  docker pull training/sinatra
Using default tag: latest
latest: Pulling from training/sinatra
a3ed95caeb02: Pull complete
6e71c809542e: Downloading [============>                       ]  17.3 MB/67.48 MB
d196a7609355: Download complete
08f6dff5acea: Download complete
ce65532003d0: Downloading [==============================>     ] 19.24 MB/21.22 MB
54bcaa4d1a10: Downloading [=====>                              ] 25.39 MB/62.67 MB
8572ad96f6e1: Waiting

下载完成后,这些 ID 中的 none 个似乎是下载的图像 ID:

docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
...
training/webapp          latest              6fae60ef3446        16 months ago       348.8 MB
training/sinatra         latest              49d952a36c58        2 years ago         447 MB

下载过程中显示的 ID 代表什么?

被拉动的是层。每个图像由多个层组成,每个层都有一个ID。该图像也有一个 ID。如果您执行 docker images -a(对于所有),那么您应该会在列表中看到其他提取的 ID。

简短回答:您在拉取图像时看到的 ID 是 "digest",它是每个图像层的 SHA256 哈希值。出现在您的本地图像列表中的图像 ID 也是一个 "digest",该摘要实际上表示图像的 JSON 配置对象的 SHA256 哈希值。

这些是图层。图像是由其他图像组成的。所有图像代表 "main image" 的图层。例如,当您使用 Dockerfile 创建新图像时,Dockerfile 中的每一行都会创建一个新层。

有关 images and layers 的更多信息,请参阅官方文档。