Skip to content

Commit 0c2b4e4

Browse files
committed
Always send attach request as streaming
Signed-off-by: Joffrey F <[email protected]>
1 parent fc6773d commit 0c2b4e4

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

docker/api/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def attach(self, container, stdout=True, stderr=True,
5050
}
5151

5252
u = self._url("/containers/{0}/attach", container)
53-
response = self._post(u, headers=headers, params=params, stream=stream)
53+
response = self._post(u, headers=headers, params=params, stream=True)
5454

5555
return self._read_from_socket(
5656
response, stream, self._check_is_tty(container)

tests/integration/api_container_test.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,20 +1092,28 @@ def test_run_container_reading_socket(self):
10921092
command = "printf '{0}'".format(line)
10931093
container = self.client.create_container(BUSYBOX, command,
10941094
detach=True, tty=False)
1095-
ident = container['Id']
1096-
self.tmp_containers.append(ident)
1095+
self.tmp_containers.append(container)
10971096

10981097
opts = {"stdout": 1, "stream": 1, "logs": 1}
1099-
pty_stdout = self.client.attach_socket(ident, opts)
1098+
pty_stdout = self.client.attach_socket(container, opts)
11001099
self.addCleanup(pty_stdout.close)
11011100

1102-
self.client.start(ident)
1101+
self.client.start(container)
11031102

11041103
next_size = next_frame_size(pty_stdout)
11051104
self.assertEqual(next_size, len(line))
11061105
data = read_exactly(pty_stdout, next_size)
11071106
self.assertEqual(data.decode('utf-8'), line)
11081107

1108+
def test_attach_no_stream(self):
1109+
container = self.client.create_container(
1110+
BUSYBOX, 'echo hello'
1111+
)
1112+
self.tmp_containers.append(container)
1113+
self.client.start(container)
1114+
output = self.client.attach(container, stream=False, logs=True)
1115+
assert output == 'hello\n'.encode(encoding='ascii')
1116+
11091117

11101118
class PauseTest(BaseAPIIntegrationTest):
11111119
def test_pause_unpause(self):

0 commit comments

Comments
 (0)