MCPcopy Index your code
hub / github.com/docker/docker-py / exec_create

Method exec_create

docker/api/exec_api.py:7–78  ·  view source on GitHub ↗

Sets up an exec instance in a running container. Args: container (str): Target container where exec instance will be created cmd (str or list): Command to be executed stdout (bool): Attach to stdout. Default: ``True``

(self, container, cmd, stdout=True, stderr=True,
                    stdin=False, tty=False, privileged=False, user='',
                    environment=None, workdir=None, detach_keys=None)

Source from the content-addressed store, hash-verified

5class ExecApiMixin:
6 @utils.check_resource('container')
7 def exec_create(self, container, cmd, stdout=True, stderr=True,
8 stdin=False, tty=False, privileged=False, user='',
9 environment=None, workdir=None, detach_keys=None):
10 """
11 Sets up an exec instance in a running container.
12
13 Args:
14 container (str): Target container where exec instance will be
15 created
16 cmd (str or list): Command to be executed
17 stdout (bool): Attach to stdout. Default: ``True``
18 stderr (bool): Attach to stderr. Default: ``True``
19 stdin (bool): Attach to stdin. Default: ``False``
20 tty (bool): Allocate a pseudo-TTY. Default: False
21 privileged (bool): Run as privileged.
22 user (str): User to execute command as. Default: root
23 environment (dict or list): A dictionary or a list of strings in
24 the following format ``["PASSWORD=xxx"]`` or
25 ``{"PASSWORD": "xxx"}``.
26 workdir (str): Path to working directory for this exec session
27 detach_keys (str): Override the key sequence for detaching
28 a container. Format is a single character `[a-Z]`
29 or `ctrl-<value>` where `<value>` is one of:
30 `a-z`, `@`, `^`, `[`, `,` or `_`.
31 ~/.docker/config.json is used by default.
32
33 Returns:
34 (dict): A dictionary with an exec ``Id`` key.
35
36 Raises:
37 :py:class:`docker.errors.APIError`
38 If the server returns an error.
39 """
40
41 if environment is not None and utils.version_lt(self._version, '1.25'):
42 raise errors.InvalidVersion(
43 'Setting environment for exec is not supported in API < 1.25'
44 )
45
46 if isinstance(cmd, str):
47 cmd = utils.split_command(cmd)
48
49 if isinstance(environment, dict):
50 environment = utils.utils.format_environment(environment)
51
52 data = {
53 'Container': container,
54 'User': user,
55 'Privileged': privileged,
56 'Tty': tty,
57 'AttachStdin': stdin,
58 'AttachStdout': stdout,
59 'AttachStderr': stderr,
60 'Cmd': cmd,
61 'Env': environment,
62 }
63
64 if workdir is not None:

Calls 3

_urlMethod · 0.80
_post_jsonMethod · 0.80
_resultMethod · 0.80