summaryrefslogtreecommitdiff
path: root/docker/models/containers.py
diff options
context:
space:
mode:
Diffstat (limited to 'docker/models/containers.py')
-rw-r--r--docker/models/containers.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/docker/models/containers.py b/docker/models/containers.py
index 1e06ed6..b33a718 100644
--- a/docker/models/containers.py
+++ b/docker/models/containers.py
@@ -6,7 +6,7 @@ from ..api import APIClient
from ..constants import DEFAULT_DATA_CHUNK_SIZE
from ..errors import (
ContainerError, DockerException, ImageNotFound,
- create_unexpected_kwargs_error
+ NotFound, create_unexpected_kwargs_error
)
from ..types import HostConfig
from ..utils import version_gte
@@ -844,7 +844,7 @@ class ContainerCollection(Collection):
return self.prepare_model(resp)
def list(self, all=False, before=None, filters=None, limit=-1, since=None,
- sparse=False):
+ sparse=False, ignore_removed=False):
"""
List containers. Similar to the ``docker ps`` command.
@@ -882,6 +882,10 @@ class ContainerCollection(Collection):
information, but guaranteed not to block. Use
:py:meth:`Container.reload` on resulting objects to retrieve
all attributes. Default: ``False``
+ ignore_removed (bool): Ignore failures due to missing containers
+ when attempting to inspect containers from the original list.
+ Set to ``True`` if race conditions are likely. Has no effect
+ if ``sparse=True``. Default: ``False``
Returns:
(list of :py:class:`Container`)
@@ -896,7 +900,15 @@ class ContainerCollection(Collection):
if sparse:
return [self.prepare_model(r) for r in resp]
else:
- return [self.get(r['Id']) for r in resp]
+ containers = []
+ for r in resp:
+ try:
+ containers.append(self.get(r['Id']))
+ # a container may have been removed while iterating
+ except NotFound:
+ if not ignore_removed:
+ raise
+ return containers
def prune(self, filters=None):
return self.client.api.prune_containers(filters=filters)