Skip to content

Commit 659090f

Browse files
committed
Adds an 'image' property to the container model
Signed-off-by: Frank Sachsenheim <[email protected]>
1 parent b585ec5 commit 659090f

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

docker/models/containers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ def name(self):
1818
if self.attrs.get('Name') is not None:
1919
return self.attrs['Name'].lstrip('/')
2020

21+
@property
22+
def image(self):
23+
"""
24+
The image of the container.
25+
"""
26+
image_id = self.attrs['Image']
27+
if image_id is None:
28+
return None
29+
return self.client.images.get(image_id.split(':')[1])
30+
2131
@property
2232
def labels(self):
2333
"""

docs/containers.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Container objects
2525
.. autoattribute:: short_id
2626
.. autoattribute:: name
2727
.. autoattribute:: status
28+
.. autoattribute:: image
2829
.. autoattribute:: labels
2930
.. py:attribute:: attrs
3031

tests/unit/models_containers_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ def test_get_archive(self):
384384
container.get_archive('foo')
385385
client.api.get_archive.assert_called_with(FAKE_CONTAINER_ID, 'foo')
386386

387+
def test_image(self):
388+
client = make_fake_client()
389+
container = client.containers.get(FAKE_CONTAINER_ID)
390+
assert container.image.id == FAKE_IMAGE_ID
391+
387392
def test_kill(self):
388393
client = make_fake_client()
389394
container = client.containers.get(FAKE_CONTAINER_ID)

0 commit comments

Comments
 (0)