docker system prune

移除未使用的资源

移除所有未使用的容器、网络、镜像(可选),以及卷(可选)。

默认情况下,不会移除卷,以防止在没有容器使用卷时意外删除重要数据。如果需要移除卷,请使用--volumes标志。

默认情况下,系统会提示确认是否继续,如果需要跳过确认步骤,请使用--force表示

-a, --all

移除所有未使用的镜像,而不仅仅是悬空镜像 (dangling images)

--filter

提供过滤值 (例如 until=<timestamp>)

-f, --force

不提示确认

--volumes

移除未使用的卷

示例

移除未使用的资源

$ docker system prune

WARNING! This will remove:
  - 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:
f97978930843610996841e065bfd2fc99478f79f535a228308c02ed3a2468301
6f753c15d0862550186718d09795029e0757279326e1074558e078c1873e35a7

Deleted Networks:
my-network

Deleted Images:
deleted: sha256:7205edb06f7df203206a4b170a484c987913364f8490a18414436c64603306f1
deleted: sha256:e0084f6764434a946851b47318f773347f98c41d1a938c35058097d745a90947

Deleted build cache objects:
6b9d8858d4a6a570c946654a1d9539d09c3132799f243004481d31061f09633e

Total reclaimed space: 115.3MB

使用过滤条件进行清理

过滤标志(--filter)的格式为key-value。如果有多个过滤器,则传递多个标志(例如 --filter "foo=bar" --filter "bif=baz"

移除包含卷的未使用资源

最后更新于