python docker SDK;获取有关悬挂的Docker映像的信息

我一直在尝试获取图像信息以尝试遵循文档:
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
...
>>>

我也尝试过其他方法,但无法弄清楚它是如何工作的.
我需要的实际上是通过悬挂或不悬挂来过滤它们.

最佳答案
按照上面的解释,它说它需要一个dict:过滤器(dict)

此外,教程示例https://docker-py.readthedocs.io/en/stable/user_guides/swarm_services.html#listing-services为过滤器提供了一个字典,尽管对于服务而言,它也应适用于图像.

因此,请尝试:

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

相关文章

最近一直在开发Apworks框架的案例代码,同时也在一起修复Apw...
最近每天都在空闲时间努力编写Apworks框架的案例代码WeText。...
在《Kubernetes中分布式存储Rook-Ceph部署快速演练》文章中,...
最近在项目中有涉及到Kubernetes的分布式存储部分的内容,也...
CentOS下Docker与.netcore(一) 之 安装 CentOS下Docker与.ne...
CentOS下Docker与.netcore(一) 之 安装 CentOS下Docker与.ne...