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.py31
1 files changed, 22 insertions, 9 deletions
diff --git a/docker/models/containers.py b/docker/models/containers.py
index 97a08b9..6ba308e 100644
--- a/docker/models/containers.py
+++ b/docker/models/containers.py
@@ -629,6 +629,9 @@ class ContainerCollection(Collection):
(e.g. ``SIGINT``).
storage_opt (dict): Storage driver options per container as a
key-value mapping.
+ stream (bool): If true and ``detach`` is false, return a log
+ generator instead of a string. Ignored if ``detach`` is true.
+ Default: ``False``.
sysctls (dict): Kernel parameters to set in the container.
tmpfs (dict): Temporary filesystems to mount, as a dictionary
mapping a path inside the container to options for that path.
@@ -696,6 +699,7 @@ class ContainerCollection(Collection):
"""
if isinstance(image, Image):
image = image.id
+ stream = kwargs.pop('stream', False)
detach = kwargs.pop("detach", False)
if detach and remove:
if version_gte(self.client.api._version, '1.25'):
@@ -723,23 +727,30 @@ class ContainerCollection(Collection):
if detach:
return container
- exit_status = container.wait()
- if exit_status != 0:
- stdout = False
- stderr = True
-
logging_driver = container.attrs['HostConfig']['LogConfig']['Type']
+ out = None
if logging_driver == 'json-file' or logging_driver == 'journald':
- out = container.logs(stdout=stdout, stderr=stderr)
- else:
+ out = container.logs(
+ stdout=stdout, stderr=stderr, stream=True, follow=True
+ )
+
+ exit_status = container.wait()
+ if exit_status != 0:
out = None
+ if not kwargs.get('auto_remove'):
+ out = container.logs(stdout=False, stderr=True)
if remove:
container.remove()
if exit_status != 0:
- raise ContainerError(container, exit_status, command, image, out)
- return out
+ raise ContainerError(
+ container, exit_status, command, image, out
+ )
+
+ return out if stream or out is None else b''.join(
+ [line for line in out]
+ )
def create(self, image, command=None, **kwargs):
"""
@@ -873,6 +884,8 @@ RUN_HOST_CONFIG_KWARGS = [
'cpu_shares',
'cpuset_cpus',
'cpuset_mems',
+ 'cpu_rt_period',
+ 'cpu_rt_runtime',
'device_read_bps',
'device_read_iops',
'device_write_bps',