1

假设我有以下图像:

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']
4

1 回答 1

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
于 2017-03-07T11:18:49.653 回答