diff --git a/docker/client.py b/docker/client.py index 47cd497f..db670afb 100644 --- a/docker/client.py +++ b/docker/client.py @@ -548,8 +548,8 @@ class Client(requests.Session): raise Exception('Exec is not supported in API < 1.15!') if isinstance(container, dict): container = container.get('Id') - if not isinstance(cmd, (list, tuple)): - cmd = [cmd] + if isinstance(cmd, six.string_types): + cmd = shlex.split(str(cmd)) data = { 'Container': container, diff --git a/tests/integration_test.py b/tests/integration_test.py index 88c69dcf..4b773ead 100644 --- a/tests/integration_test.py +++ b/tests/integration_test.py @@ -630,7 +630,8 @@ class TestRestartingContainer(BaseTestCase): class TestExecuteCommand(BaseTestCase): def runTest(self): - container = self.client.create_container('busybox', ['false']) + container = self.client.create_container('busybox', 'cat', + detach=True, stdin_open=True) id = container['Id'] self.client.start(id) self.tmp_containers.append(id) @@ -640,9 +641,23 @@ class TestExecuteCommand(BaseTestCase): self.assertEqual(res, expected) +class TestExecuteCommandString(BaseTestCase): + def runTest(self): + container = self.client.create_container('busybox', 'cat', + detach=True, stdin_open=True) + id = container['Id'] + self.client.start(id) + self.tmp_containers.append(id) + + res = self.client.execute(id, 'echo hello world', stdout=True) + expected = b'hello world\n' if six.PY3 else 'hello world\n' + self.assertEqual(res, expected) + + class TestExecuteCommandStreaming(BaseTestCase): def runTest(self): - container = self.client.create_container('busybox', ['false']) + container = self.client.create_container('busybox', 'cat', + detach=True, stdin_open=True) id = container['Id'] self.client.start(id) self.tmp_containers.append(id)