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

Method exec_run

docker/models/containers.py:167–223  ·  view source on GitHub ↗

Run a command inside this container. Similar to ``docker exec``. Args: cmd (str or list): Command to be executed stdout (bool): Attach to stdout. Default: ``True`` stderr (bool): Attach to stderr. Default: ``True`` stdin (bool

(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
                 privileged=False, user='', detach=False, stream=False,
                 socket=False, environment=None, workdir=None, demux=False)

Source from the content-addressed store, hash-verified

165 return self.client.api.diff(self.id)
166
167 def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
168 privileged=False, user='', detach=False, stream=False,
169 socket=False, environment=None, workdir=None, demux=False):
170 """
171 Run a command inside this container. Similar to
172 ``docker exec``.
173
174 Args:
175 cmd (str or list): Command to be executed
176 stdout (bool): Attach to stdout. Default: ``True``
177 stderr (bool): Attach to stderr. Default: ``True``
178 stdin (bool): Attach to stdin. Default: ``False``
179 tty (bool): Allocate a pseudo-TTY. Default: False
180 privileged (bool): Run as privileged.
181 user (str): User to execute command as. Default: root
182 detach (bool): If true, detach from the exec command.
183 Default: False
184 stream (bool): Stream response data. Default: False
185 socket (bool): Return the connection socket to allow custom
186 read/write operations. Default: False
187 environment (dict or list): A dictionary or a list of strings in
188 the following format ``["PASSWORD=xxx"]`` or
189 ``{"PASSWORD": "xxx"}``.
190 workdir (str): Path to working directory for this exec session
191 demux (bool): Return stdout and stderr separately
192
193 Returns:
194 (ExecResult): A tuple of (exit_code, output)
195 exit_code: (int):
196 Exit code for the executed command or ``None`` if
197 either ``stream`` or ``socket`` is ``True``.
198 output: (generator, bytes, or tuple):
199 If ``stream=True``, a generator yielding response chunks.
200 If ``socket=True``, a socket object for the connection.
201 If ``demux=True``, a tuple of two bytes: stdout and stderr.
202 A bytestring containing response data otherwise.
203
204 Raises:
205 :py:class:`docker.errors.APIError`
206 If the server returns an error.
207 """
208 resp = self.client.api.exec_create(
209 self.id, cmd, stdout=stdout, stderr=stderr, stdin=stdin, tty=tty,
210 privileged=privileged, user=user, environment=environment,
211 workdir=workdir,
212 )
213 exec_output = self.client.api.exec_start(
214 resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket,
215 demux=demux
216 )
217 if socket or stream:
218 return ExecResult(None, exec_output)
219
220 return ExecResult(
221 self.client.api.exec_inspect(resp['Id'])['ExitCode'],
222 exec_output
223 )
224

Callers 4

test_exec_run_successMethod · 0.80
test_exec_run_failedMethod · 0.80
test_exec_runMethod · 0.80
test_exec_run_failureMethod · 0.80

Calls 3

exec_createMethod · 0.80
exec_startMethod · 0.80
exec_inspectMethod · 0.80

Tested by 4

test_exec_run_successMethod · 0.64
test_exec_run_failedMethod · 0.64
test_exec_runMethod · 0.64
test_exec_run_failureMethod · 0.64