Search code examples
dockerdocker-machinedocker-imagepruning

docker image prune is not working for version < 1.13


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'.`

Solution

  • 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.