The exec API lets you run arbitrary commands inside a running container. The workflow is always: create an exec instance → start it → optionally inspect or resize it. All methods are on theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fussybeaver/bollard/llms.txt
Use this file to discover all available pages before exploring further.
Docker struct. The ExecConfig struct lives in bollard::models; the helper CreateExecOptions and StartExecOptions types live in bollard::exec.
Types
CreateExecOptions<T>
A convenience wrapper around bollard::models::ExecConfig. It is generic over T: Into<String> + Serialize, so you can use &str or String for all string fields.
Into<ExecConfig> so it can be passed directly to create_exec. Alternatively, construct bollard::models::ExecConfig directly.
StartExecOptions
detach: true the exec runs in the background and start_exec returns StartExecResults::Detached immediately. When detach: false (the default) the call upgrades the connection and returns StartExecResults::Attached.
StartExecResults
Attached provides a Stream of LogOutput items and an AsyncWrite handle for sending data to the command’s stdin.
LogOutput
Display (UTF-8 lossy decode), AsRef<[u8]>, and provides into_bytes() -> Bytes. Use Display or into_bytes() to extract the content.
ResizeExecOptions
Into<crate::query_parameters::ResizeExecOptions>.
Methods
create_exec
start_exec next.
Arguments:
container_name— Name or ID of a running container.config— Either aCreateExecOptions<T>or abollard::models::ExecConfig.
ExecConfig key fields (bollard::models::ExecConfig):
| Field | Type | Description |
|---|---|---|
attach_stdin | Option<bool> | Attach to the command’s stdin. |
attach_stdout | Option<bool> | Attach to the command’s stdout. |
attach_stderr | Option<bool> | Attach to the command’s stderr. |
tty | Option<bool> | Allocate a pseudo-TTY. |
cmd | Option<Vec<String>> | Command to run as an array (e.g. ["ps", "-ef"]). |
env | Option<Vec<String>> | Extra environment variables (["KEY=value", …]). |
working_dir | Option<String> | Working directory inside the container. |
user | Option<String> | User/group to run as ("user", "user:group", "uid", "uid:gid"). |
privileged | Option<bool> | Run with extended privileges. |
detach_keys | Option<String> | Key sequence for detaching (e.g. "ctrl-c"). |
CreateExecResults — contains id: String (the exec instance ID to pass to start_exec).
start_exec
- When
configisNoneordetach: false, the call upgrades the HTTP connection and streams output asStartExecResults::Attached. - When
detach: true, the exec runs in the background andStartExecResults::Detachedis returned immediately.
exec_id— Theidreturned bycreate_exec.config— OptionalStartExecOptions. PassNonefor attached mode with defaults.
StartExecResults
inspect_exec
bollard::models::ExecInspectResponse
Key fields of ExecInspectResponse:
| Field | Type | Description |
|---|---|---|
id | Option<String> | Exec instance ID. |
running | Option<bool> | Whether the exec is still running. |
exit_code | Option<i64> | Exit code of the process (available once running is false). |
pid | Option<i64> | PID of the exec process inside the container. |
process_config | Option<ProcessConfig> | Command and arguments as configured. |
resize_exec
tty: true was set in create_exec and the exec was started in attached mode.
Options: bollard::exec::ResizeExecOptions (or ResizeExecOptionsBuilder from bollard::query_parameters)
| Field | Type | Description |
|---|---|---|
height | u16 | New height in rows. |
width | u16 | New width in columns. |
()
Full Exec Example
The
output_capacity field of StartExecOptions controls the internal buffer size for the FramedRead decoder. The default is 8 * 1024 bytes. Increase it when executing commands that produce very long single lines of output.