RunCommand

Struct RunCommand 

Source
pub struct RunCommand {
    pub executor: CommandExecutor,
    /* private fields */
}
Expand description

Docker run command builder with fluent API

Fields§

§executor: CommandExecutor

Command executor for extensibility

Implementations§

Source§

impl RunCommand

Source

pub fn new(image: impl Into<String>) -> Self

Create a new run command for the specified image

Source

pub fn name(self, name: impl Into<String>) -> Self

Set the container name

Source

pub fn detach(self) -> Self

Run in detached mode (background)

Source

pub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self

Add an environment variable

Source

pub fn envs(self, vars: HashMap<String, String>) -> Self

Add multiple environment variables

Source

pub fn port(self, host_port: u16, container_port: u16) -> Self

Add a port mapping

Source

pub fn dynamic_port(self, container_port: u16) -> Self

Add a dynamic port mapping (Docker assigns host port)

Source

pub fn port_dyn(self, container_port: u16) -> Self

Alias for dynamic_port() - Add a dynamic port mapping (Docker assigns host port)

Source

pub fn volume( self, source: impl Into<String>, target: impl Into<String>, ) -> Self

Add a volume mount

Source

pub fn bind(self, source: impl Into<String>, target: impl Into<String>) -> Self

Add a bind mount

Source

pub fn volume_ro( self, source: impl Into<String>, target: impl Into<String>, ) -> Self

Add a read-only volume mount

Source

pub fn workdir(self, workdir: impl Into<PathBuf>) -> Self

Set working directory

Source

pub fn entrypoint(self, entrypoint: impl Into<String>) -> Self

Override entrypoint

Source

pub fn cmd(self, command: Vec<String>) -> Self

Set command to run in container

Source

pub fn interactive(self) -> Self

Enable interactive mode

Source

pub fn tty(self) -> Self

Allocate a TTY

Source

pub fn remove(self) -> Self

Remove container automatically when it exits

Source

pub fn rm(self) -> Self

Alias for remove() - Remove container automatically when it exits (–rm flag)

Source

pub fn it(self) -> Self

Convenience method for interactive TTY mode

Source

pub fn memory(self, memory: impl Into<String>) -> Self

Set memory limit (e.g., “1g”, “512m”)

Source

pub fn cpus(self, cpus: impl Into<String>) -> Self

Set number of CPUs (e.g., “2.0”, “1.5”)

Source

pub fn cpu_shares(self, shares: i64) -> Self

Set CPU shares (relative weight)

Source

pub fn cpu_period(self, period: i64) -> Self

Set CPU CFS period in microseconds

Source

pub fn cpu_quota(self, quota: i64) -> Self

Set CPU CFS quota in microseconds

Source

pub fn cpuset_cpus(self, cpus: impl Into<String>) -> Self

Set CPUs in which to allow execution (e.g., “0-3”, “0,1”)

Source

pub fn cpuset_mems(self, mems: impl Into<String>) -> Self

Set MEMs in which to allow execution (e.g., “0-3”, “0,1”)

Source

pub fn memory_swap(self, swap: impl Into<String>) -> Self

Set memory + swap limit (e.g., “2g”, “-1” for unlimited)

Source

pub fn memory_reservation(self, reservation: impl Into<String>) -> Self

Set memory soft limit (e.g., “500m”)

Source

pub fn user(self, user: impl Into<String>) -> Self

Set username or UID (format: <name|uid>[:<group|gid>])

Source

pub fn privileged(self) -> Self

Give extended privileges to this container

Source

pub fn hostname(self, hostname: impl Into<String>) -> Self

Set container host name

Source

pub fn restart(self, restart: impl Into<String>) -> Self

Set restart policy (e.g., “always”, “unless-stopped”, “on-failure”, “no”)

Source

pub fn platform(self, platform: impl Into<String>) -> Self

Set platform if server is multi-platform capable (e.g., “linux/amd64”)

Source

pub fn runtime(self, runtime: impl Into<String>) -> Self

Set runtime to use for this container

Source

pub fn isolation(self, isolation: impl Into<String>) -> Self

Set container isolation technology

Source

pub fn pull(self, pull: impl Into<String>) -> Self

Set pull image policy (“always”, “missing”, “never”)

Source

pub fn cidfile(self, cidfile: impl Into<String>) -> Self

Write the container ID to the specified file

Source

pub fn domainname(self, domainname: impl Into<String>) -> Self

Set container NIS domain name

Source

pub fn mac_address(self, mac: impl Into<String>) -> Self

Set container MAC address (e.g., “92:d0:c6:0a:29:33”)

Source

pub fn log_driver(self, driver: impl Into<String>) -> Self

Set logging driver for the container

Source

pub fn volume_driver(self, driver: impl Into<String>) -> Self

Set optional volume driver for the container

Source

pub fn userns(self, userns: impl Into<String>) -> Self

Set user namespace to use

Source

pub fn uts(self, uts: impl Into<String>) -> Self

Set UTS namespace to use

Source

pub fn pid(self, pid: impl Into<String>) -> Self

Set PID namespace to use

Source

pub fn ipc(self, ipc: impl Into<String>) -> Self

Set IPC mode to use

Source

pub fn cgroupns(self, cgroupns: impl Into<String>) -> Self

Set cgroup namespace to use (host|private)

Source

pub fn cgroup_parent(self, parent: impl Into<String>) -> Self

Set optional parent cgroup for the container

Source

pub fn kernel_memory(self, memory: impl Into<String>) -> Self

Set kernel memory limit

Source

pub fn memory_swappiness(self, swappiness: i32) -> Self

Tune container memory swappiness (0 to 100)

Source

pub fn oom_score_adj(self, score: i32) -> Self

Tune host’s OOM preferences (-1000 to 1000)

Source

pub fn pids_limit(self, limit: i64) -> Self

Tune container pids limit (set -1 for unlimited)

Source

pub fn shm_size(self, size: impl Into<String>) -> Self

Set size of /dev/shm (e.g., “64m”)

Source

pub fn stop_signal(self, signal: impl Into<String>) -> Self

Set signal to stop the container (e.g., “SIGTERM”, “SIGKILL”)

Source

pub fn stop_timeout(self, timeout: i32) -> Self

Set timeout (in seconds) to stop a container

Source

pub fn detach_keys(self, keys: impl Into<String>) -> Self

Override the key sequence for detaching a container

Source

pub fn no_sig_proxy(self) -> Self

Disable proxying received signals to the process

Source

pub fn read_only(self) -> Self

Mount the container’s root filesystem as read only

Source

pub fn init(self) -> Self

Run an init inside the container that forwards signals and reaps processes

Source

pub fn oom_kill_disable(self) -> Self

Disable OOM Killer

Source

pub fn no_healthcheck(self) -> Self

Disable any container-specified HEALTHCHECK

Source

pub fn enable_content_trust(self) -> Self

Enable image verification (disable content trust is false)

Source

pub fn publish_all(self) -> Self

Publish all exposed ports to random ports

Source

pub fn quiet(self) -> Self

Suppress the pull output

Source

pub fn dns(self, dns: impl Into<String>) -> Self

Add custom DNS server

Source

pub fn dns_servers(self, servers: Vec<String>) -> Self

Add multiple DNS servers

Source

pub fn dns_option(self, option: impl Into<String>) -> Self

Add DNS option

Add DNS search domain

Source

pub fn add_host(self, mapping: impl Into<String>) -> Self

Add host-to-IP mapping (format: “hostname:ip”)

Source

pub fn cap_add(self, capability: impl Into<String>) -> Self

Add Linux capability

Source

pub fn cap_drop(self, capability: impl Into<String>) -> Self

Drop Linux capability

Source

pub fn security_opt(self, option: impl Into<String>) -> Self

Add security option

Source

pub fn device(self, device: impl Into<String>) -> Self

Add host device to container

Source

pub fn tmpfs(self, path: impl Into<String>) -> Self

Mount tmpfs directory

Source

pub fn expose(self, port: impl Into<String>) -> Self

Expose port without publishing it

Source

pub fn env_file(self, file: impl Into<PathBuf>) -> Self

Read environment variables from file

Source

pub fn label(self, label: impl Into<String>) -> Self

Add metadata label

Source

pub fn label_file(self, file: impl Into<PathBuf>) -> Self

Read labels from file

Source

pub fn network_alias(self, alias: impl Into<String>) -> Self

Add network alias for the container

Source

pub fn group_add(self, group: impl Into<String>) -> Self

Add supplementary group for the user

Source

pub fn attach(self, stream: impl Into<String>) -> Self

Attach to STDIN, STDOUT or STDERR

Source

pub fn log_opt(self, option: impl Into<String>) -> Self

Add log driver option

Source

pub fn storage_opt(self, option: impl Into<String>) -> Self

Add storage driver option

Source

pub fn ulimit(self, limit: impl Into<String>) -> Self

Set ulimit option

Source

pub fn volumes_from(self, container: impl Into<String>) -> Self

Mount volumes from another container

Add link to another container (deprecated)

Add container IPv4/IPv6 link-local address

Source

pub fn health_cmd(self, cmd: impl Into<String>) -> Self

Set health check command

Source

pub fn health_interval(self, interval: impl Into<String>) -> Self

Set health check interval

Source

pub fn health_retries(self, retries: i32) -> Self

Set health check retries

Source

pub fn health_timeout(self, timeout: impl Into<String>) -> Self

Set health check timeout

Source

pub fn health_start_period(self, period: impl Into<String>) -> Self

Set health check start period

Source

pub fn health_start_interval(self, interval: impl Into<String>) -> Self

Set health check start interval

Source

pub fn mount(self, mount: impl Into<String>) -> Self

Add advanced mount configuration

Source

pub fn network(self, network: impl Into<String>) -> Self

Connect to a network

Source

pub fn gpus(self, gpus: impl Into<String>) -> Self

Set GPU devices to add to the container

Source

pub fn annotation( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Add custom annotation (key=value format)

Source

pub fn sysctl(self, key: impl Into<String>, value: impl Into<String>) -> Self

Set kernel parameter (key=value format)

Source

pub fn blkio_weight(self, weight: u16) -> Self

Set block IO weight (10-1000)

Source

pub fn blkio_weight_device(self, device_weight: impl Into<String>) -> Self

Set block IO weight for a specific device (format: DEVICE:WEIGHT)

Source

pub fn device_read_bps(self, device_rate: impl Into<String>) -> Self

Limit read rate (bytes per second) from a device (format: DEVICE:RATE)

Source

pub fn device_write_bps(self, device_rate: impl Into<String>) -> Self

Limit write rate (bytes per second) to a device (format: DEVICE:RATE)

Source

pub fn device_read_iops(self, device_rate: impl Into<String>) -> Self

Limit read rate (IO per second) from a device (format: DEVICE:RATE)

Source

pub fn device_write_iops(self, device_rate: impl Into<String>) -> Self

Limit write rate (IO per second) to a device (format: DEVICE:RATE)

Source

pub fn cpu_rt_period(self, period: i64) -> Self

Limit CPU real-time period in microseconds

Source

pub fn cpu_rt_runtime(self, runtime: i64) -> Self

Limit CPU real-time runtime in microseconds

Source

pub fn ip(self, ip: impl Into<String>) -> Self

Set container IPv4 address (e.g., “172.30.100.104”)

Source

pub fn ip6(self, ip6: impl Into<String>) -> Self

Set container IPv6 address (e.g., “2001:db8::33”)

Source

pub fn device_cgroup_rule(self, rule: impl Into<String>) -> Self

Add device cgroup rule

Source§

impl RunCommand

Source

pub async fn stream<F>(&self, handler: F) -> Result<StreamResult>
where F: FnMut(OutputLine) + Send + 'static,

Run the container with streaming output

Note: This will fail if the container is run in detached mode.

§Examples
use docker_wrapper::RunCommand;
use docker_wrapper::StreamHandler;

let result = RunCommand::new("alpine")
    .cmd(vec!["echo".to_string(), "Hello, World!".to_string()])
    .stream(StreamHandler::print())
    .await?;
§Errors

Returns an error if the container is detached or encounters an I/O error

Trait Implementations§

Source§

impl Clone for RunCommand

Source§

fn clone(&self) -> RunCommand

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RunCommand

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DockerCommand for RunCommand

Source§

type Output = ContainerId

The output type this command produces
Source§

fn get_executor(&self) -> &CommandExecutor

Get the command executor for extensibility
Source§

fn get_executor_mut(&mut self) -> &mut CommandExecutor

Get mutable command executor for extensibility
Source§

fn build_command_args(&self) -> Vec<String>

Build the complete command arguments including subcommands
Source§

fn execute<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the command and return the typed output
Source§

fn execute_command<'life0, 'async_trait>( &'life0 self, command_args: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<CommandOutput>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Helper method to execute the command with proper error handling
Source§

fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self

Add a raw argument to the command (escape hatch)
Source§

fn args<I, S>(&mut self, args: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Add multiple raw arguments to the command (escape hatch)
Source§

fn flag(&mut self, flag: &str) -> &mut Self

Add a flag option (e.g., –detach, –rm)
Source§

fn option(&mut self, key: &str, value: &str) -> &mut Self

Add a key-value option (e.g., –name value, –env key=value)
Source§

impl StreamableCommand for RunCommand

Source§

fn stream<'life0, 'async_trait, F>( &'life0 self, handler: F, ) -> Pin<Box<dyn Future<Output = Result<StreamResult>> + Send + 'async_trait>>
where F: FnMut(OutputLine) + Send + 'static + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Run the command with streaming output Read more
Source§

fn stream_channel<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(Receiver<OutputLine>, StreamResult)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Run the command with streaming output via a channel Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,