summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2017-12-19 13:21:56 -0800
committerJoffrey F <joffrey@docker.com>2017-12-19 13:51:47 -0800
commit598f16771ca4673886c3ea9b86fa280d77829beb (patch)
tree4e986b245772c35f1d00f853a778ddf5c549260e
parentf10c008aa57c4c48cce1a718a0160a54a2b1a371 (diff)
downloaddocker-py-2.7.0-release.tar.gz
Don't attempt to retrieve container's stderr if `auto_remove` was set2.7.0-release
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r--docker/models/containers.py4
-rw-r--r--tests/integration/models_containers_test.py14
2 files changed, 16 insertions, 2 deletions
diff --git a/docker/models/containers.py b/docker/models/containers.py
index f16b7cd..6ba308e 100644
--- a/docker/models/containers.py
+++ b/docker/models/containers.py
@@ -737,7 +737,9 @@ class ContainerCollection(Collection):
exit_status = container.wait()
if exit_status != 0:
- out = container.logs(stdout=False, stderr=True)
+ out = None
+ if not kwargs.get('auto_remove'):
+ out = container.logs(stdout=False, stderr=True)
if remove:
container.remove()
diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py
index 7707ae2..d246189 100644
--- a/tests/integration/models_containers_test.py
+++ b/tests/integration/models_containers_test.py
@@ -1,5 +1,7 @@
-import docker
import tempfile
+
+import docker
+import pytest
from .base import BaseIntegrationTest, TEST_API_VERSION
from ..helpers import random_name, requires_api_version
@@ -114,6 +116,16 @@ class ContainerCollectionTest(BaseIntegrationTest):
)
assert out == b'hello\n'
+ @requires_api_version('1.25')
+ def test_run_with_auto_remove_error(self):
+ client = docker.from_env(version=TEST_API_VERSION)
+ with pytest.raises(docker.errors.ContainerError) as e:
+ client.containers.run(
+ 'alpine', 'sh -c ">&2 echo error && exit 1"', auto_remove=True
+ )
+ assert e.value.exit_status == 1
+ assert e.value.stderr is None
+
def test_run_with_streamed_logs(self):
client = docker.from_env(version=TEST_API_VERSION)
out = client.containers.run(