加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 03:22:00 所属栏目:安全 来源:网络整理
导读:我一直在尝试获取图像信息以尝试遵循文档: 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,the

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读