diff --git a/docker/models/containers.py b/docker/models/containers.py index 9c9e92c90f..6c5ccc6543 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -829,9 +829,10 @@ def run(self, image, command=None, stdout=True, stderr=False, The container logs, either ``STDOUT``, ``STDERR``, or both, depending on the value of the ``stdout`` and ``stderr`` arguments. - ``STDOUT`` and ``STDERR`` may be read only if either ``json-file`` - or ``journald`` logging driver used. Thus, if you are using none of - these drivers, a ``None`` object is returned instead. See the + ``STDOUT`` and ``STDERR`` may be read only if a ``json-file``, + ``journald``, or ``local`` logging driver is used. Thus, if you + are using none of these drivers, a ``None`` object is returned + instead. See the `Engine API documentation `_ for full details. @@ -889,7 +890,7 @@ def run(self, image, command=None, stdout=True, stderr=False, logging_driver = container.attrs['HostConfig']['LogConfig']['Type'] out = None - if logging_driver == 'json-file' or logging_driver == 'journald': + if logging_driver in ('json-file', 'journald', 'local'): out = container.logs( stdout=stdout, stderr=stderr, stream=True, follow=True ) diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py index 0e2ae341a9..85ccde8af5 100644 --- a/tests/unit/models_containers_test.py +++ b/tests/unit/models_containers_test.py @@ -33,6 +33,19 @@ def test_run(self): follow=True ) + def test_run_local_logging_driver(self): + client = make_fake_client() + inspected = client.api.inspect_container.return_value + inspected['HostConfig']['LogConfig']['Type'] = 'local' + + out = client.containers.run("alpine", "echo hello world") + + assert out == b'hello world\n' + client.api.logs.assert_called_with( + FAKE_CONTAINER_ID, stderr=False, stdout=True, stream=True, + follow=True + ) + def test_create_container_args(self): networking_config = { 'foo': EndpointConfig(