1、docker system prune 简介
docker system prune 命令用于显示有关 Docker 系统的详细信息,包括 Docker 版本、操作系统信息、容器和镜像的数量等。
删除所有未使用的容器、网络、图像(包括悬空和未引用的),以及可选的卷。
参考文档:https://docs.docker.com/engine/reference/commandline/system_prune/
2、docker system prune 语法
docker system prune [OPTIONS]
3、docker system prune 命令
docker system prune
WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
f44f9b81948b3919590d5f79a680d8378f1139b41952e219830a33027c80c867
792776e68ac9d75bce4092bc1b5cc17b779bc926ab04f4185aec9bf1c0d4641f
Deleted Networks:
network1
network2
Deleted Images:
untagged: hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
deleted: sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57
deleted: sha256:45761469c965421a92a69cc50e92c01e0cfa94fe026cdd1233445ea00e96289a
Total reclaimed space: 1.84kB默认情况下,为了防止删除重要数据,卷不会被删除,如果当前没有容器使用该卷。在运行命令时使用 --volumes 标志来清理卷数据:
docker system prune -a --volumes
WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all volumes not used by at least one container
        - all images without at least one container associated to them
        - all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
0998aa37185a1a7036b0e12cf1ac1b6442dcfa30a5c9650a42ed5010046f195b
73958bfb884fa81fa4cc6baf61055667e940ea2357b4036acbbe25a60f442a4d
Deleted Networks:
my-network-a
my-network-b
Deleted Volumes:
named-vol
Deleted Images:
untagged: my-curl:latest
deleted: sha256:7d88582121f2a29031d92017754d62a0d1a215c97e8f0106c586546e7404447d
deleted: sha256:dd14a93d83593d4024152f85d7c63f76aaa4e73e228377ba1d130ef5149f4d8b
untagged: alpine:3.3
deleted: sha256:695f3d04125db3266d4ab7bbb3c6b23aa4293923e762aa2562c54f49a28f009f
untagged: alpine:latest
deleted: sha256:ee4603260daafe1a8c2f3b78fd760922918ab2441cbb2853ed5c439e59c52f96
deleted: sha256:9007f5987db353ec398a223bc5a135c5a9601798ba20a1abba537ea2f8ac765f
deleted: sha256:71fa90c8f04769c9721459d5aa0936db640b92c8c91c9b589b54abd412d120ab
deleted: sha256:bb1c3357b3c30ece26e6604aea7d2ec0ace4166ff34c3616701279c22444c0f3
untagged: my-jq:latest
deleted: sha256:6e66d724542af9bc4c4abf4a909791d7260b6d0110d8e220708b09e4ee1322e1
deleted: sha256:07b3fa89d4b17009eb3988dfc592c7d30ab3ba52d2007832dffcf6d40e3eda7f
deleted: sha256:3a88a5c81eb5c283e72db2dbc6d65cbfd8e80b6c89bb6e714cfaaa0eed99c548
Total reclaimed space: 13.5 MB1)过滤器 (--filter)
过滤器标志 (--filter) 的格式为 "key=value"。如果有多个过滤器,则可以传递多个标志(例如,--filter "foo=bar" --filter "bif=baz")。
当前支持的过滤器包括:
- until (<timestamp>) - 仅删除在给定时间戳之前创建的容器、镜像和网络
- label (label=<key>, label=<key>=<value>, label!=<key>, 或 label!=<key>=<value>) - 仅删除具有指定标签(或不具有指定标签,如果使用了label!=...)的容器、镜像、网络和卷。
until 过滤器可以使用 Unix 时间戳、日期格式化时间戳或相对于守护程序机器时间计算的 Go 时长字符串(例如 10m、1h30m)。支持的日期格式化时间戳包括 RFC3339Nano、RFC3339、2006-01-02T15:04:05、2006-01-02T15:04:05.999999999、2006-01-02Z07:00 和 2006-01-02。如果未在时间戳的末尾提供 Z 或 +-00:00 时区偏移量,则使用守护程序的本地时区。当提供 Unix 时间戳时,输入秒数[.纳秒],其中秒数是从1970年1月1日(午夜 UTC/GMT)开始经过的秒数,不包括闰秒(也称为 Unix 纪元或 Unix 时间),可选的 .纳秒字段是不超过九位数字的秒的一部分。
标签过滤器接受两种格式。一种是 label=... (label=<key> or label=<key>=<value>),它会删除具有指定标签的容器、镜像、网络和卷。另一种格式是 label!=... (label!=<key> or label!=<key>=<value>),它会删除没有指定标签的容器、镜像、网络和卷。
4、命令选项
| 选项 | 描述 | 
| --all, -a | 删除所有未使用的镜像,而不仅仅是悬空的镜像 | 
| --filter | 提供过滤器的值(例如,label==) | 
| --force, -f | 无需确认即可执行操作 | 
| --volumes | 清理卷数据 | 
5、子命令
| 命令 | 描述 | 
| docker system df | 显示 Docker 磁盘使用情况 | 
| docker system events | 获取服务器的实时事件 | 
| docker system info | 显示系统范围的信息 | 
| docker system prune | 删除未使用的数据 |