说我有以下图片:
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.site.org:4000/project/my_backend latest d8f4b42c0cae 5 days ago 189 MB
docker.site.org:4000/project/my_backend v1.6.1 d8f4b42c0cae 5 days ago 189 MB
docker.site.org:4000/project/my_daemon latest b8a28fa9fa9c 5 days ago 865 MB
docker.site.org:4000/project/my_daemon v1.6.1 652e925c18f3 5 days ago 865 MB
docker.site.org:4000/project/my_daemon v1.6.0 e6cff3d768d4 5 days ago 865 MB
如何使用my_daemon
列出docker-py
图片的标签以获取此输出(订单无关紧要)?
['v1.6.1', 'v1.6.0', 'latest']
答案 0 :(得分:0)
def test_list_available_daemons_version(self):
images = mock.get_images()
versions = container_services.available_versions(images, name='project/my_daemon')
self.assertEqual(len(versions), 3)
self.assertCountEqual(set(versions), {'latest', 'v1.6.1', 'v1.6.0'})
def available_versions(images=[], name='project/my_daemon'):
versions = []
for image in images:
tags = image['RepoTags']
for tag in tags:
if name in tag:
version = tag.split(':')[-1]
versions.append(version)
return versions