python docker sdk;获取关于悬挂docker图像的信息

2024-04-20 03:22:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经尝试了一段时间来获取图像信息,尝试按照文档: This doc specifically

list(**kwargs)

List images on the server.

Parameters:

  • name (str) -- Only show images belonging to the repository name
  • all (bool) -- Show intermediate image layers. By default, these are filtered out.
  • filters (dict) -- Filters to be processed on the image list. Available filters: - dangling (bool) - label (str): format either key or key=value

现在,当我尝试和我已经尝试了很多事情,我不能找出正确的语法:

sh-4.2# python
Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import docker
>>> client = docker.from_env()
>>> for image in client.images.list('dangling'):
...     print image.id
...
>>> for image in client.images.list('dangling=true'):
...     print image.id
...
>>>

我也试过其他东西,但就是不知道它是怎么工作的。 我需要的是通过悬挂与否来过滤它们。你知道吗


Tags: thetokeynameimageclientdefaultfor
1条回答
网友
1楼 · 发布于 2024-04-20 03:22:50

根据上面的解释,它需要一个dict:filters (dict)

此外,https://docker-py.readthedocs.io/en/stable/user_guides/swarm_services.html#listing-services中的教程示例为过滤器提供了dict,尽管对于服务,它也应该适用于图像。你知道吗

因此,请尝试:

client.images.list(filters={'dangling': True})

相关问题 更多 >