名称¶
podman-system-prune - 移除所有未使用的 Pod、容器、镜像、网络和卷数据
简介¶
podman system prune [选项]
描述¶
podman system prune 从本地存储中移除所有未使用的容器(包括悬空和未引用的)、构建容器、Pod、网络,以及可选的卷。
使用 --all 选项删除所有未使用的镜像。未使用的镜像包括悬空镜像以及任何没有基于其创建的容器的镜像。
默认情况下,卷不会被移除,以防止在当前没有容器使用该卷时删除重要数据。运行命令时使用 --volumes 标志可同时修剪卷。
默认情况下,构建容器不会被移除,以防止干扰正在进行的构建。运行命令时使用 --build 标志可同时移除构建容器。
选项¶
--all, -a¶
递归移除所有未使用的 Pod、容器、镜像、网络和卷数据。(最多 50 次迭代。)
--build¶
移除在构建期间创建但由于构建意外终止而未移除的任何构建容器。
注意:这不是安全操作,只应在没有正在进行的构建时执行。它可能会干扰正在进行的构建。
--external¶
尝试清理存储 JSON 文件中未引用的先前容器或层的残留。这些情况可能发生在不干净关机或瞬态存储模式下的常规重启时。
然而,当使用瞬态存储模式时,Podman 数据库不会持久化。这意味着容器在重启后会在磁盘上留下可写层。当使用瞬态存储时,建议在启动时运行 podman system prune --external 命令。
此选项与 --all 和 --filter 不兼容,并会放弃移除未使用资源的默认行为。
--filter=过滤器¶
提供过滤值。
过滤器 参数的格式为 key=value
。如果有多个过滤器,则传递多个选项:--filter foo=bar --filter bif=baz。
支持的过滤器
过滤器 |
描述 |
---|---|
label |
仅移除带有(或不带有,在使用 label!=[…] 时)指定标签的容器和镜像。 |
until |
仅移除在给定时间戳之前创建的容器和镜像。 |
label
过滤器 接受两种格式。一种是 label
=key 或 label
=key=value,它移除带有指定标签的容器和镜像。另一种格式是 label!
=key 或 label!
=key=value,它移除不带指定标签的容器和镜像。
until
filter 可以是 Unix 时间戳、日期格式时间戳或相对于机器时间计算的 Go duration 字符串(例如 10m, 1h30m)。
--force, -f¶
不提示确认
--help, -h¶
打印用法说明
--volumes¶
修剪当前未被任何容器使用的卷。
示例¶
修剪所有容器、Pod、网络和悬空镜像。
$ podman system prune
WARNING! This command removes:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
修剪所有未使用的容器、Pod 和网络。
$ podman system prune --all
WARNING! This command removes:
- all stopped containers
- all networks not used by at least one container
- all images without at least one container associated with them
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Images
ce21f047f73644dcb9cd55ad247433fb47ade48ad4f4e676881fbcb2d5735c76
c874afc1f445044eaa821da0c32328707406e546a688d8c4c22587a5f88a1992
2fce09cfad57c6de112654eeb6f6da1851f3ced1cff7ac0002378642c2c7ca84
0cd6d2e072175191823999cd189f8d262ba5e460271095570d8cffb1d9072e9a
172bdaffe628cc7b7f8b7b6695438afc612a9833382f5968a06740a3804c3b64
bf07fec943ec23054f3b81c0e65926a1c83dc82c50933dc6372c60e09fdb2d4f
b2f735cbb571dd6a28e66455af0623ecc81f9c5b74259d3e04b3bac3b178e965
cea2ff433c610f5363017404ce989632e12b953114fefc6f597a58e813c15d61
Deleted Networks
podman-default-kube-network
Total reclaimed space: 3.372GB
修剪所有容器、构建容器、Pod、网络和悬空镜像。
$ podman system prune --build
WARNING! This command removes:
- all stopped containers
- all networks not used by at least one container
- all build containers
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N] y
Deleted Containers
a8bfed41990114767c933d27bf5508b01cdc0f641dc36037b349648347c6ea64
Deleted Images
055733a33e7a78efa27d3c682df97a9e0489133bef071745144c8d0edda2d708
Total reclaimed space: 1.4GB
按标签修剪容器。
$ podman system prune --filter label=role=cleanup
WARNING! This command removes:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N] y
Deleted Containers
5cd96fb787274db888f8b587c3690be1edea25b7f66b030037c528e2cea10b34
Total reclaimed space: 24.55kB
修剪容器,直到。$ podman system prune --filter until=2m 警告!此命令将移除:- 所有已停止的容器 - 未被至少一个容器使用的所有网络 - 所有悬空镜像 - 所有悬空构建缓存
您确定要继续吗?[y/N] y 已删除容器 a12f9f6f2d901bc145c1e2c27dc8e5e2d04050854f4d9e01a6e10b1019e2d345 0d08f2e467cbff04b63ccd83efeb6ccc6161f54c27d5100d1194defe7ea73cf7 815dc403e1bc85bfa4a9d3184cbbe77fd019ea66780bf0b42e8726d5956d9bd3 回收总空间:74.14KB
With `--force` flag
$ podman system prune --force 回收总空间:0B
## SEE ALSO
**[podman(1)](podman.1.md)**, **[podman-system(1)](podman-system.1.md)**
## HISTORY
February 2019, Originally compiled by Dan Walsh (dwalsh at redhat dot com)
December 2020, converted filter information from docs.docker.com documentation by Dan Walsh (dwalsh at redhat dot com)