Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use Prune so that it gets all of the images? #1939

Closed
cinjon opened this issue Mar 2, 2018 · 8 comments
Closed

How do I use Prune so that it gets all of the images? #1939

cinjon opened this issue Mar 2, 2018 · 8 comments

Comments

@cinjon
Copy link

cinjon commented Mar 2, 2018

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?

@NateBrady23
Copy link

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.

@robsco-git
Copy link

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

@rodrigodlima
Copy link

rodrigodlima commented Apr 30, 2018

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.

[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()
[<Image: 'docker.io/nginx:1.12.2'>, <Image: 'docker.io/nginx:latest'>, <Image: 'docker.io/alpine:latest'>]
>>> 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

@rsjethani
Copy link

rsjethani commented May 25, 2018

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

@shin-
Copy link
Contributor

shin- commented May 25, 2018

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})

@shin- shin- closed this as completed May 25, 2018
@rsjethani
Copy link

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

@rsjethani
Copy link

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

@denisgolius
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants