Docker-py: How do I use Prune so that it gets all of the images?

Created on 2 Mar 2018  路  8Comments  路  Source: docker/docker-py

I built an image and then afterward ran client.images.prune(). The returned dict stated {'ImagesDeleted': None, 'SpaceReclaimed': 0}. I then ran docker system prune -a -f and saw that it deleted a lot of space (~1gb). I then tried client.images.remove, but that also did nothing.

What's the correct way of pruning the system from docker-py?

Most helpful comment

The -a option in the CLI is equivalent to setting the dangling filter to false. (according to https://github.com/docker/cli/blob/master/cli/command/image/prune.go#L59)

In short, docker image prune -a -f translates as such: client.images.prune(filters={'dangling': False})

All 8 comments

Running into the same issue, there are actually prunes for everything:

client.containers.prune()
client.images.prune()
client.networks.prune()
client.volumes.prune()

Note that you're just calling it on images.

There also seems to be a discrepancy between using the Python API and the Docker command line for me.

For me, the client.images.prune() don't works too. For example, I have one image nginx:1.12.2 that is not in use for any container, when I run the client.images.prune(), this image is not removed.

```Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import docker
client = docker.from_env()
client.images.list()
[, , ]
client.images.prune()
{u'SpaceReclaimed': 0, u'ImagesDeleted': None}
````
[root@localhost ~]# docker image prune -a -f
Deleted Images:
untagged: docker.io/nginx:1.12.2

I get the same behavior as @rodrigodlima has with server api version 1.37

The -a option in the CLI is equivalent to setting the dangling filter to false. (according to https://github.com/docker/cli/blob/master/cli/command/image/prune.go#L59)

In short, docker image prune -a -f translates as such: client.images.prune(filters={'dangling': False})

yes that worked! Thanks. Do we have 'until' filter available?

Ahh yes 'until' filter also works. But its not mentioned in the docs

The -a option in the CLI is equivalent to setting the dangling filter to false. (according to https://github.com/docker/cli/blob/master/cli/command/image/prune.go#L59)

In short, docker image prune -a -f translates as such: client.images.prune(filters={'dangling': False})

How to sort docker containers as it's do the command ?
docker image prune -a --filter "until=72h"

Was this page helpful?
0 / 5 - 0 ratings