This commit is contained in:
Stuart 2025-01-23 10:17:21 +00:00 committed by GitHub
commit dac746bf78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -32,6 +32,12 @@ class Container(Model):
"""
if self.attrs.get('Name') is not None:
return self.attrs['Name'].lstrip('/')
if self.attrs.get('Names') is not None:
stripped_names = [name.lstrip('/') for name in self.attrs['Names']]
for name in stripped_names:
if '/' not in name:
return name
return ','.join(stripped_names)
@property
def image(self):

View File

@ -302,7 +302,7 @@ class ContainerCollectionTest(BaseIntegrationTest):
def test_list_sparse(self):
client = docker.from_env(version=TEST_API_VERSION)
container_id = client.containers.run(
"alpine", "sleep 300", detach=True).id
"alpine", "sleep 300", detach=True, name='a_container').id
self.tmp_containers.append(container_id)
containers = [c for c in client.containers.list(sparse=True) if c.id ==
container_id]
@ -312,6 +312,7 @@ class ContainerCollectionTest(BaseIntegrationTest):
assert container.attrs['Image'] == 'alpine'
assert container.status == 'running'
assert container.image == client.images.get('alpine')
assert container.name == 'a_container'
with pytest.raises(docker.errors.DockerException):
_ = container.labels