docker 图片修剪不适用于版本 < 1.13

docker image prune is not working for version < 1.13

已尝试以下命令,但其中 none 个命令删除了图像。

sudo docker images prune --filter "dangling=true"
sudo docker images prune --all
sudo docker images prune -a
sudo docker images prune

两个命令的输出:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

Docker版本:

$ sudo docker version
Client:
Version:      1.12.6
API version:  1.24
Go version:   go1.6.4
Git commit:   78d1802
Built:        Tue Jan 10 20:26:30 2017
OS/Arch:      linux/amd64

Server:
Version:      1.12.6
API version:  1.24
Go version:   go1.6.4
Git commit:   78d1802
Built:        Tue Jan 10 20:26:30 2017
OS/Arch:      linux/amd64 

Docker doc 建议使用此命令,但我遇到了错误

$ sudo docker image prune -a
docker: 'image' is not a docker command.
See 'docker --help'.`

你应该使用 docker image prune --filter "dangling=true"。它应该是 image 而不是 images.

另请注意,在删除悬挂图像的情况下,您无需指定过滤器,因为默认情况下 prune command 会删除悬挂图像:

Remove all dangling images. If -a is specified, will also remove all images not referenced by any container.

查看 docker image prune and API 1.25 - 对于 Docker 引擎 1.13,API 版本为 1.25

Remove unused images

The client and daemon API must both be at least 1.25 to use this command. Use the docker version command on the client to check your client and daemon API versions.

你运行宁版本:1.12.6API版本:1.24,所以你需要更新你的版本才能 运行 docker image p运行e.

如果您不想(或不能)升级,您可以使用没有指定 API 版本的 docker rmi or docker image rm,所以我希望两者都能正常工作。