From 4a1e7aeaff75ddaa925230e6ee6698397102f329 Mon Sep 17 00:00:00 2001 From: yeasy Date: Sat, 22 Aug 2026 23:30:10 -0700 Subject: [PATCH] =?UTF-8?q?fix(4.2):=20Engine=2029=20=E8=B5=B7=20docker=20?= =?UTF-8?q?image=20ls=20=E9=BB=98=E8=AE=A4=E4=B8=8D=E5=86=8D=E5=88=97?= =?UTF-8?q?=E5=87=BA=E8=99=9A=E6=82=AC=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4.2.5 用一条裸 `docker images` 演示 `` 行,但本书 1.1 的版本提示写明 「本书内容及示例基于 Docker Engine v29.x 及以上版本」,而这条输出在 29 上 不可能出现:docker/cli#6574(2025-10-29 合入,随 29.0 发布)把无标签镜像 从默认列表里拿掉了,Engine 29 发行说明写作 "docker image ls no longer shows untagged images by default if no --all flag is provided",官方 `docker image ls` 参考页的 Description 现在也是 "Untagged (dangling) images are also hidden by default. Use the -a (--all) flag to show intermediate layers and dangling images."(该页 Examples 里的老输出反而还没跟上,以 Description 与发行说明为准)。 示例改用本节自己后面就在推荐的 `-f dangling=true`,并把这条默认行为写进导语。 4.2.6 「-a 会显示很多无标签镜像——这些是构建过程中产生的中间层」同步补上虚悬镜像 ——`-a` 的官方说明正是 "default hides intermediate and dangling images",两类 都藏,只说中间层会让读者以为虚悬镜像仍在默认列表里。 --- 04_image/4.2_list.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/04_image/4.2_list.md b/04_image/4.2_list.md index 670bdc4..215b70d 100644 --- a/04_image/4.2_list.md +++ b/04_image/4.2_list.md @@ -125,14 +125,14 @@ $ docker images -f label=maintainer=example@email.com ### 4.2.5 虚悬镜像 -在镜像列表里,你可能会看到一些仓库名和标签都为 `` 的镜像,这类镜像被称为虚悬镜像。 +仓库名和标签都为 `` 的镜像被称为虚悬镜像。自 Docker Engine 29 起,`docker image ls` 默认不再列出它们,需要 `-a` 或 `dangling=true` 过滤器才能看到。 #### 什么是虚悬镜像 仓库名和标签都显示为 `` 的镜像: ```bash -$ docker images +$ docker images -f dangling=true REPOSITORY TAG IMAGE ID SIZE 00285df0df87 342MB ``` @@ -157,14 +157,14 @@ $ docker image prune ### 4.2.6 中间层镜像 -除了虚悬镜像,`docker image ls` 默认列出的只是顶层镜像。还有一种镜像是为了加速镜像构建、重复利用资源而存在的中间层镜像。 +`docker image ls` 默认列出的只是有标签的顶层镜像。除了虚悬镜像,被隐藏的还有一类为了加速镜像构建、重复利用资源而存在的中间层镜像。 #### 查看所有镜像:包含中间层 ```bash $ docker images -a ``` -会显示很多无标签镜像——这些是构建过程中产生的中间层,被其他镜像依赖。 +会显示默认隐藏的镜像:构建过程中产生的中间层,以及上面提到的虚悬镜像。中间层被其他镜像依赖。 > ⚠️ 不要删除中间层镜像。它们是其他镜像的依赖,删除会导致上层镜像无法使用。删除顶层镜像时会自动清理不再需要的中间层。