MCPcopy
hub / github.com/docker/docker-py / attach

Method attach

docker/api/container.py:16–67  ·  view source on GitHub ↗

Attach to a container. The ``.logs()`` function is a wrapper around this method, which you can use instead if you want to fetch/stream container output without first retrieving the entire backlog. Args: container (str): The container to attach t

(self, container, stdout=True, stderr=True,
               stream=False, logs=False, demux=False)

Source from the content-addressed store, hash-verified

14class ContainerApiMixin:
15 @utils.check_resource('container')
16 def attach(self, container, stdout=True, stderr=True,
17 stream=False, logs=False, demux=False):
18 """
19 Attach to a container.
20
21 The ``.logs()`` function is a wrapper around this method, which you can
22 use instead if you want to fetch/stream container output without first
23 retrieving the entire backlog.
24
25 Args:
26 container (str): The container to attach to.
27 stdout (bool): Include stdout.
28 stderr (bool): Include stderr.
29 stream (bool): Return container output progressively as an iterator
30 of strings, rather than a single string.
31 logs (bool): Include the container's previous output.
32 demux (bool): Keep stdout and stderr separate.
33
34 Returns:
35 By default, the container's output as a single string (two if
36 ``demux=True``: one for stdout and one for stderr).
37
38 If ``stream=True``, an iterator of output strings. If
39 ``demux=True``, two iterators are returned: one for stdout and one
40 for stderr.
41
42 Raises:
43 :py:class:`docker.errors.APIError`
44 If the server returns an error.
45 """
46 params = {
47 'logs': logs and 1 or 0,
48 'stdout': stdout and 1 or 0,
49 'stderr': stderr and 1 or 0,
50 'stream': stream and 1 or 0
51 }
52
53 headers = {
54 'Connection': 'Upgrade',
55 'Upgrade': 'tcp'
56 }
57
58 u = self._url("/containers/{0}/attach", container)
59 response = self._post(u, headers=headers, params=params, stream=True)
60
61 output = self._read_from_socket(
62 response, stream, self._check_is_tty(container), demux=demux)
63
64 if stream:
65 return CancellableStream(output, response)
66 else:
67 return output
68
69 @utils.check_resource('container')
70 def attach_socket(self, container, params=None, ws=False):

Callers

nothing calls this directly

Calls 5

CancellableStreamClass · 0.85
_urlMethod · 0.80
_postMethod · 0.80
_read_from_socketMethod · 0.80
_check_is_ttyMethod · 0.80

Tested by

no test coverage detected