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
impl RunCommand
Sourcepub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn env(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add an environment variable
Sourcepub fn dynamic_port(self, container_port: u16) -> Self
pub fn dynamic_port(self, container_port: u16) -> Self
Add a dynamic port mapping (Docker assigns host port)
Sourcepub fn port_dyn(self, container_port: u16) -> Self
pub fn port_dyn(self, container_port: u16) -> Self
Alias for dynamic_port()
- Add a dynamic port mapping (Docker assigns host port)
Sourcepub fn volume(
self,
source: impl Into<String>,
target: impl Into<String>,
) -> Self
pub fn volume( self, source: impl Into<String>, target: impl Into<String>, ) -> Self
Add a volume mount
Sourcepub fn bind(self, source: impl Into<String>, target: impl Into<String>) -> Self
pub fn bind(self, source: impl Into<String>, target: impl Into<String>) -> Self
Add a bind mount
Sourcepub fn volume_ro(
self,
source: impl Into<String>,
target: impl Into<String>,
) -> Self
pub fn volume_ro( self, source: impl Into<String>, target: impl Into<String>, ) -> Self
Add a read-only volume mount
Sourcepub fn entrypoint(self, entrypoint: impl Into<String>) -> Self
pub fn entrypoint(self, entrypoint: impl Into<String>) -> Self
Override entrypoint
Sourcepub fn interactive(self) -> Self
pub fn interactive(self) -> Self
Enable interactive mode
Sourcepub fn rm(self) -> Self
pub fn rm(self) -> Self
Alias for remove()
- Remove container automatically when it exits (–rm flag)
Set CPU shares (relative weight)
Sourcepub fn cpu_period(self, period: i64) -> Self
pub fn cpu_period(self, period: i64) -> Self
Set CPU CFS period in microseconds
Sourcepub fn cpuset_cpus(self, cpus: impl Into<String>) -> Self
pub fn cpuset_cpus(self, cpus: impl Into<String>) -> Self
Set CPUs in which to allow execution (e.g., “0-3”, “0,1”)
Sourcepub fn cpuset_mems(self, mems: impl Into<String>) -> Self
pub fn cpuset_mems(self, mems: impl Into<String>) -> Self
Set MEMs in which to allow execution (e.g., “0-3”, “0,1”)
Sourcepub fn memory_swap(self, swap: impl Into<String>) -> Self
pub fn memory_swap(self, swap: impl Into<String>) -> Self
Set memory + swap limit (e.g., “2g”, “-1” for unlimited)
Sourcepub fn memory_reservation(self, reservation: impl Into<String>) -> Self
pub fn memory_reservation(self, reservation: impl Into<String>) -> Self
Set memory soft limit (e.g., “500m”)
Sourcepub fn user(self, user: impl Into<String>) -> Self
pub fn user(self, user: impl Into<String>) -> Self
Set username or UID (format: <name|uid>[:<group|gid>])
Sourcepub fn privileged(self) -> Self
pub fn privileged(self) -> Self
Give extended privileges to this container
Sourcepub fn restart(self, restart: impl Into<String>) -> Self
pub fn restart(self, restart: impl Into<String>) -> Self
Set restart policy (e.g., “always”, “unless-stopped”, “on-failure”, “no”)
Sourcepub fn platform(self, platform: impl Into<String>) -> Self
pub fn platform(self, platform: impl Into<String>) -> Self
Set platform if server is multi-platform capable (e.g., “linux/amd64”)
Sourcepub fn isolation(self, isolation: impl Into<String>) -> Self
pub fn isolation(self, isolation: impl Into<String>) -> Self
Set container isolation technology
Sourcepub fn pull(self, pull: impl Into<String>) -> Self
pub fn pull(self, pull: impl Into<String>) -> Self
Set pull image policy (“always”, “missing”, “never”)
Sourcepub fn cidfile(self, cidfile: impl Into<String>) -> Self
pub fn cidfile(self, cidfile: impl Into<String>) -> Self
Write the container ID to the specified file
Sourcepub fn domainname(self, domainname: impl Into<String>) -> Self
pub fn domainname(self, domainname: impl Into<String>) -> Self
Set container NIS domain name
Sourcepub fn mac_address(self, mac: impl Into<String>) -> Self
pub fn mac_address(self, mac: impl Into<String>) -> Self
Set container MAC address (e.g., “92:d0:c6:0a:29:33”)
Sourcepub fn log_driver(self, driver: impl Into<String>) -> Self
pub fn log_driver(self, driver: impl Into<String>) -> Self
Set logging driver for the container
Sourcepub fn volume_driver(self, driver: impl Into<String>) -> Self
pub fn volume_driver(self, driver: impl Into<String>) -> Self
Set optional volume driver for the container
Sourcepub fn cgroupns(self, cgroupns: impl Into<String>) -> Self
pub fn cgroupns(self, cgroupns: impl Into<String>) -> Self
Set cgroup namespace to use (host|private)
Sourcepub fn cgroup_parent(self, parent: impl Into<String>) -> Self
pub fn cgroup_parent(self, parent: impl Into<String>) -> Self
Set optional parent cgroup for the container
Sourcepub fn kernel_memory(self, memory: impl Into<String>) -> Self
pub fn kernel_memory(self, memory: impl Into<String>) -> Self
Set kernel memory limit
Sourcepub fn memory_swappiness(self, swappiness: i32) -> Self
pub fn memory_swappiness(self, swappiness: i32) -> Self
Tune container memory swappiness (0 to 100)
Sourcepub fn oom_score_adj(self, score: i32) -> Self
pub fn oom_score_adj(self, score: i32) -> Self
Tune host’s OOM preferences (-1000 to 1000)
Sourcepub fn pids_limit(self, limit: i64) -> Self
pub fn pids_limit(self, limit: i64) -> Self
Tune container pids limit (set -1 for unlimited)
Sourcepub fn stop_signal(self, signal: impl Into<String>) -> Self
pub fn stop_signal(self, signal: impl Into<String>) -> Self
Set signal to stop the container (e.g., “SIGTERM”, “SIGKILL”)
Sourcepub fn stop_timeout(self, timeout: i32) -> Self
pub fn stop_timeout(self, timeout: i32) -> Self
Set timeout (in seconds) to stop a container
Sourcepub fn detach_keys(self, keys: impl Into<String>) -> Self
pub fn detach_keys(self, keys: impl Into<String>) -> Self
Override the key sequence for detaching a container
Sourcepub fn no_sig_proxy(self) -> Self
pub fn no_sig_proxy(self) -> Self
Disable proxying received signals to the process
Sourcepub fn init(self) -> Self
pub fn init(self) -> Self
Run an init inside the container that forwards signals and reaps processes
Sourcepub fn oom_kill_disable(self) -> Self
pub fn oom_kill_disable(self) -> Self
Disable OOM Killer
Sourcepub fn no_healthcheck(self) -> Self
pub fn no_healthcheck(self) -> Self
Disable any container-specified HEALTHCHECK
Sourcepub fn enable_content_trust(self) -> Self
pub fn enable_content_trust(self) -> Self
Enable image verification (disable content trust is false)
Sourcepub fn publish_all(self) -> Self
pub fn publish_all(self) -> Self
Publish all exposed ports to random ports
Sourcepub fn dns_servers(self, servers: Vec<String>) -> Self
pub fn dns_servers(self, servers: Vec<String>) -> Self
Add multiple DNS servers
Sourcepub fn dns_option(self, option: impl Into<String>) -> Self
pub fn dns_option(self, option: impl Into<String>) -> Self
Add DNS option
Sourcepub fn dns_search(self, domain: impl Into<String>) -> Self
pub fn dns_search(self, domain: impl Into<String>) -> Self
Add DNS search domain
Sourcepub fn add_host(self, mapping: impl Into<String>) -> Self
pub fn add_host(self, mapping: impl Into<String>) -> Self
Add host-to-IP mapping (format: “hostname:ip”)
Sourcepub fn security_opt(self, option: impl Into<String>) -> Self
pub fn security_opt(self, option: impl Into<String>) -> Self
Add security option
Sourcepub fn label_file(self, file: impl Into<PathBuf>) -> Self
pub fn label_file(self, file: impl Into<PathBuf>) -> Self
Read labels from file
Sourcepub fn network_alias(self, alias: impl Into<String>) -> Self
pub fn network_alias(self, alias: impl Into<String>) -> Self
Add network alias for the container
Sourcepub fn storage_opt(self, option: impl Into<String>) -> Self
pub fn storage_opt(self, option: impl Into<String>) -> Self
Add storage driver option
Sourcepub fn volumes_from(self, container: impl Into<String>) -> Self
pub fn volumes_from(self, container: impl Into<String>) -> Self
Mount volumes from another container
Sourcepub fn link_local_ip(self, ip: impl Into<String>) -> Self
pub fn link_local_ip(self, ip: impl Into<String>) -> Self
Add container IPv4/IPv6 link-local address
Sourcepub fn health_cmd(self, cmd: impl Into<String>) -> Self
pub fn health_cmd(self, cmd: impl Into<String>) -> Self
Set health check command
Sourcepub fn health_interval(self, interval: impl Into<String>) -> Self
pub fn health_interval(self, interval: impl Into<String>) -> Self
Set health check interval
Sourcepub fn health_retries(self, retries: i32) -> Self
pub fn health_retries(self, retries: i32) -> Self
Set health check retries
Sourcepub fn health_timeout(self, timeout: impl Into<String>) -> Self
pub fn health_timeout(self, timeout: impl Into<String>) -> Self
Set health check timeout
Sourcepub fn health_start_period(self, period: impl Into<String>) -> Self
pub fn health_start_period(self, period: impl Into<String>) -> Self
Set health check start period
Sourcepub fn health_start_interval(self, interval: impl Into<String>) -> Self
pub fn health_start_interval(self, interval: impl Into<String>) -> Self
Set health check start interval
Sourcepub fn annotation(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn annotation( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add custom annotation (key=value format)
Sourcepub fn sysctl(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn sysctl(self, key: impl Into<String>, value: impl Into<String>) -> Self
Set kernel parameter (key=value format)
Sourcepub fn blkio_weight(self, weight: u16) -> Self
pub fn blkio_weight(self, weight: u16) -> Self
Set block IO weight (10-1000)
Sourcepub fn blkio_weight_device(self, device_weight: impl Into<String>) -> Self
pub fn blkio_weight_device(self, device_weight: impl Into<String>) -> Self
Set block IO weight for a specific device (format: DEVICE:WEIGHT)
Sourcepub fn device_read_bps(self, device_rate: impl Into<String>) -> Self
pub fn device_read_bps(self, device_rate: impl Into<String>) -> Self
Limit read rate (bytes per second) from a device (format: DEVICE:RATE)
Sourcepub fn device_write_bps(self, device_rate: impl Into<String>) -> Self
pub fn device_write_bps(self, device_rate: impl Into<String>) -> Self
Limit write rate (bytes per second) to a device (format: DEVICE:RATE)
Sourcepub fn device_read_iops(self, device_rate: impl Into<String>) -> Self
pub fn device_read_iops(self, device_rate: impl Into<String>) -> Self
Limit read rate (IO per second) from a device (format: DEVICE:RATE)
Sourcepub fn device_write_iops(self, device_rate: impl Into<String>) -> Self
pub fn device_write_iops(self, device_rate: impl Into<String>) -> Self
Limit write rate (IO per second) to a device (format: DEVICE:RATE)
Sourcepub fn cpu_rt_period(self, period: i64) -> Self
pub fn cpu_rt_period(self, period: i64) -> Self
Limit CPU real-time period in microseconds
Sourcepub fn cpu_rt_runtime(self, runtime: i64) -> Self
pub fn cpu_rt_runtime(self, runtime: i64) -> Self
Limit CPU real-time runtime in microseconds
Sourcepub fn ip(self, ip: impl Into<String>) -> Self
pub fn ip(self, ip: impl Into<String>) -> Self
Set container IPv4 address (e.g., “172.30.100.104”)
Sourcepub fn ip6(self, ip6: impl Into<String>) -> Self
pub fn ip6(self, ip6: impl Into<String>) -> Self
Set container IPv6 address (e.g., “2001:db8::33
”)
Sourcepub fn device_cgroup_rule(self, rule: impl Into<String>) -> Self
pub fn device_cgroup_rule(self, rule: impl Into<String>) -> Self
Add device cgroup rule
Source§impl RunCommand
impl RunCommand
Sourcepub async fn stream<F>(&self, handler: F) -> Result<StreamResult>
pub async fn stream<F>(&self, handler: F) -> Result<StreamResult>
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
impl Clone for RunCommand
Source§fn clone(&self) -> RunCommand
fn clone(&self) -> RunCommand
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more