fix(4.2): Engine 29 起 docker image ls 默认不再列出虚悬镜像

4.2.5 用一条裸 `docker images` 演示 `<none>` 行,但本书 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",两类
都藏,只说中间层会让读者以为虚悬镜像仍在默认列表里。
This commit is contained in:
yeasy
2026-08-22 23:30:10 -07:00
parent 6a5c6631df
commit 4a1e7aeaff
+4 -4
View File
@@ -125,14 +125,14 @@ $ docker images -f label=maintainer=example@email.com
### 4.2.5 虚悬镜像
在镜像列表里,你可能会看到一些仓库名和标签都为 `<none>` 的镜像,这类镜像被称为虚悬镜像。
仓库名和标签都为 `<none>` 的镜像被称为虚悬镜像。自 Docker Engine 29 起,`docker image ls` 默认不再列出它们,需要 `-a` 或 `dangling=true` 过滤器才能看到。
#### 什么是虚悬镜像
仓库名和标签都显示为 `<none>` 的镜像:
```bash
$ docker images
$ docker images -f dangling=true
REPOSITORY TAG IMAGE ID SIZE
<none> <none> 00285df0df87 342MB
```
@@ -157,14 +157,14 @@ $ docker image prune
### 4.2.6 中间层镜像
除了虚悬镜像,`docker image ls` 默认列出的只是顶层镜像。还有一种镜像是为了加速镜像构建、重复利用资源而存在的中间层镜像。
`docker image ls` 默认列出的只是有标签的顶层镜像。除了虚悬镜像,被隐藏的还有一类为了加速镜像构建、重复利用资源而存在的中间层镜像。
#### 查看所有镜像:包含中间层
```bash
$ docker images -a
```
会显示很多无标签镜像——这些是构建过程中产生的中间层,被其他镜像依赖。
会显示默认隐藏的镜像:构建过程中产生的中间层,以及上面提到的虚悬镜像。中间层被其他镜像依赖。
> ⚠️ 不要删除中间层镜像。它们是其他镜像的依赖,删除会导致上层镜像无法使用。删除顶层镜像时会自动清理不再需要的中间层。