docker-py client.images.list() always shows all images

3.6k Views Asked by At

I'm not able to filter images from client.images.list()

https://docker-py.readthedocs.io/en/stable/images.html#docker.models.images.ImageCollection.list

The documentation says "name (str) – Only show images belonging to the repository name"

client.images.list(name="elixir")

EXPECTATION:

[<Image: 'elixir:1.10-alpine'>]

ACTUAL:

[<Image: 'postgres:latest'>, <Image: 'node:15-alpine'>, <Image: 'elixir:1.10-alpine'>, <Image: 'nginx:stable-alpine'>]

Bug?

Versions:

Docker version 20.10.0, build 7287ab3

>>> import docker
>>> docker.__version__
'4.4.0'
2

There are 2 best solutions below

3
On

I had to use:-

client.images.list(filters = { "reference" : "elixir:1.10-alpine"})

To return a list of images, Martins response appears to be missing the 's' off images

1
On

client.images.list(filters = { "reference" : "elixir:1.10-alpine"}) will give you what you want.

I used https://docs.docker.com/engine/api/v1.41/#operation/ImageList as the source of my inspiration.