4
4
5
5
from ..api import APIClient
6
6
from ..constants import DEFAULT_DATA_CHUNK_SIZE
7
- from ..errors import (ContainerError , ImageNotFound ,
8
- create_unexpected_kwargs_error )
7
+ from ..errors import (
8
+ ContainerError , DockerException , ImageNotFound ,
9
+ create_unexpected_kwargs_error
10
+ )
9
11
from ..types import HostConfig
10
12
from ..utils import version_gte
11
13
from .images import Image
@@ -27,7 +29,7 @@ def image(self):
27
29
"""
28
30
The image of the container.
29
31
"""
30
- image_id = self .attrs ['Image' ]
32
+ image_id = self .attrs . get ( 'ImageID' , self . attrs ['Image' ])
31
33
if image_id is None :
32
34
return None
33
35
return self .client .images .get (image_id .split (':' )[1 ])
@@ -37,15 +39,23 @@ def labels(self):
37
39
"""
38
40
The labels of a container as dictionary.
39
41
"""
40
- result = self .attrs ['Config' ].get ('Labels' )
41
- return result or {}
42
+ try :
43
+ result = self .attrs ['Config' ].get ('Labels' )
44
+ return result or {}
45
+ except KeyError :
46
+ raise DockerException (
47
+ 'Label data is not available for sparse objects. Call reload()'
48
+ ' to retrieve all information'
49
+ )
42
50
43
51
@property
44
52
def status (self ):
45
53
"""
46
54
The status of the container. For example, ``running``, or ``exited``.
47
55
"""
48
- return self .attrs ['State' ]['Status' ]
56
+ if isinstance (self .attrs ['State' ], dict ):
57
+ return self .attrs ['State' ]['Status' ]
58
+ return self .attrs ['State' ]
49
59
50
60
def attach (self , ** kwargs ):
51
61
"""
@@ -863,14 +873,16 @@ def list(self, all=False, before=None, filters=None, limit=-1, since=None,
863
873
container. Give the container name or id.
864
874
- `since` (str): Only containers created after a particular
865
875
container. Give container name or id.
866
- sparse (bool): Do not inspect containers. Returns partial
867
- informations, but guaranteed not to block. Use reload() on
868
- each container to get the full list of attributes.
869
876
870
877
A comprehensive list can be found in the documentation for
871
878
`docker ps
872
879
<https://docs.docker.com/engine/reference/commandline/ps>`_.
873
880
881
+ sparse (bool): Do not inspect containers. Returns partial
882
+ information, but guaranteed not to block. Use
883
+ :py:meth:`Container.reload` on resulting objects to retrieve
884
+ all attributes. Default: ``False``
885
+
874
886
Returns:
875
887
(list of :py:class:`Container`)
876
888
0 commit comments