4

Have tried the following commands, but none of them delete the images.

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

Output for both the commands:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

Docker version:

$ 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 suggests this command, but I encountered error

$ sudo docker image prune -a
docker: 'image' is not a docker command.
See 'docker --help'.`
Steve
  • 381
  • 1
  • 6
  • 16

2 Answers2

5

You should use docker image prune --filter "dangling=true". It should be image instead of images.

Also note that in the case of removing dangling images, you don't need to specify a filter, since by default the prune command removes dangling images:

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

yamenk
  • 46,736
  • 10
  • 93
  • 87
  • Just now edited the question with the confirmation. Tried with docker image prune, but got error. – Steve Jun 14 '18 at 08:17
  • 1
    Well said! Ideally docker command should respond with "Did you mean 'docker image prune' when trying to use 'docker images prune'" – Ville Laitila Mar 30 '19 at 20:43
3

Looking at the docker image prune and API 1.25 - For Docker Engine 1.13, the API version is 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.

And you're running Version: 1.12.6 and API version: 1.24, so you need to update your version to be able to run docker image prune.

If you don't want to (or can't) upgrade you can use docker rmi or docker image rm which don't have a specified API versions, so I expect both to work.

namokarm
  • 668
  • 1
  • 7
  • 20
  • 2
    `docker rmi` worked. `docker image rm` threw the error as mentioned in the question. Thanks – Steve Jun 15 '18 at 11:20