r"""Run a command inside this container. Similar to `docker exec`. Args: task (TaskConfig): The configuration for the task. Returns: (ExecResult): A tuple of (exit_code, output) exit_code: (int): Exit code for the executed
(
self,
task: TaskConfig,
)
| 136 | return self |
| 137 | |
| 138 | def exec_run( |
| 139 | self, |
| 140 | task: TaskConfig, |
| 141 | ) -> Any: |
| 142 | r"""Run a command inside this container. Similar to `docker exec`. |
| 143 | |
| 144 | Args: |
| 145 | task (TaskConfig): The configuration for the task. |
| 146 | |
| 147 | Returns: |
| 148 | (ExecResult): A tuple of (exit_code, output) |
| 149 | exit_code: (int): |
| 150 | Exit code for the executed command or `None` if |
| 151 | either `stream` or `socket` is `True`. |
| 152 | output: (generator, bytes, or tuple): |
| 153 | If `stream=True`, a generator yielding response chunks. |
| 154 | If `socket=True`, a socket object for the connection. |
| 155 | If `demux=True`, a tuple of two bytes: stdout and stderr. |
| 156 | A bytestring containing response data otherwise. |
| 157 | |
| 158 | Raises: |
| 159 | RuntimeError: If the container does not exist. |
| 160 | """ |
| 161 | if not self.container: |
| 162 | raise RuntimeError( |
| 163 | "Container does not exist. Please build the container first." |
| 164 | ) |
| 165 | |
| 166 | return self.container.exec_run(**task.model_dump()) |
| 167 | |
| 168 | def build(self, time_out: int = 15) -> "DockerRuntime": |
| 169 | r"""Build the Docker container and start it. |
no test coverage detected