pub struct Container {Show 22 fields
pub name: String,
pub container_id: Option<String>,
pub image: Option<String>,
pub config: HashMap<String, String>,
pub ports: Vec<String>,
pub volumes: Vec<String>,
pub env_vars: HashMap<String, String>,
pub network: Option<String>,
pub network_aliases: Vec<String>,
pub cpu_limit: Option<String>,
pub memory_limit: Option<String>,
pub memory_swap_limit: Option<String>,
pub cpu_shares: Option<String>,
pub restart_policy: Option<String>,
pub health_check: Option<HealthCheck>,
pub detach: bool,
pub snapshotter: Option<String>,
pub runtime: Option<String>,
pub disk_limit: Option<String>,
pub annotations: HashMap<String, String>,
pub privileged: bool,
pub devices: Vec<String>,
}Expand description
Container struct for nerdctl operations
Fields§
§name: StringName of the container
container_id: Option<String>Container ID
image: Option<String>Base image (if created from an image)
config: HashMap<String, String>Configuration options
ports: Vec<String>Port mappings
volumes: Vec<String>Volume mounts
env_vars: HashMap<String, String>Environment variables
network: Option<String>Network to connect to
network_aliases: Vec<String>Network aliases
cpu_limit: Option<String>CPU limit
memory_limit: Option<String>Memory limit
memory_swap_limit: Option<String>Memory swap limit
CPU shares
restart_policy: Option<String>Restart policy
health_check: Option<HealthCheck>Health check
detach: boolWhether to run in detached mode
snapshotter: Option<String>Snapshotter to use
runtime: Option<String>Runtime to use (e.g., “kata-runtime”, “runc”)
disk_limit: Option<String>Disk size limit (for Kata containers, sets VM block device size)
annotations: HashMap<String, String>OCI annotations (key-value pairs passed to runtime)
privileged: boolWhether to run the container in privileged mode
devices: Vec<String>Device mounts (e.g., “/dev/net/tun”)
Implementations§
Source§impl Container
impl Container
Sourcepub fn new(name: &str) -> Result<Self, NerdctlError>
pub fn new(name: &str) -> Result<Self, NerdctlError>
Sourcepub fn from_image(name: &str, image: &str) -> Result<Self, NerdctlError>
pub fn from_image(name: &str, image: &str) -> Result<Self, NerdctlError>
Source§impl Container
impl Container
Sourcepub fn reset(self) -> Self
pub fn reset(self) -> Self
Reset the container configuration to defaults while keeping the name and image If the container exists, it will be stopped and removed.
§Returns
Self- The container instance for method chaining
Sourcepub fn with_ports(self, ports: &[&str]) -> Self
pub fn with_ports(self, ports: &[&str]) -> Self
Sourcepub fn with_volume(self, volume: &str) -> Self
pub fn with_volume(self, volume: &str) -> Self
Sourcepub fn with_volumes(self, volumes: &[&str]) -> Self
pub fn with_volumes(self, volumes: &[&str]) -> Self
Sourcepub fn with_network(self, network: &str) -> Self
pub fn with_network(self, network: &str) -> Self
Sourcepub fn with_network_alias(self, alias: &str) -> Self
pub fn with_network_alias(self, alias: &str) -> Self
Sourcepub fn with_network_aliases(self, aliases: &[&str]) -> Self
pub fn with_network_aliases(self, aliases: &[&str]) -> Self
Sourcepub fn with_cpu_limit(self, cpus: &str) -> Self
pub fn with_cpu_limit(self, cpus: &str) -> Self
Sourcepub fn with_memory_limit(self, memory: &str) -> Self
pub fn with_memory_limit(self, memory: &str) -> Self
Sourcepub fn with_memory_swap_limit(self, memory_swap: &str) -> Self
pub fn with_memory_swap_limit(self, memory_swap: &str) -> Self
Sourcepub fn with_restart_policy(self, policy: &str) -> Self
pub fn with_restart_policy(self, policy: &str) -> Self
Sourcepub fn with_health_check(self, cmd: &str) -> Self
pub fn with_health_check(self, cmd: &str) -> Self
Sourcepub fn with_health_check_options(
self,
cmd: &str,
interval: Option<&str>,
timeout: Option<&str>,
retries: Option<u32>,
start_period: Option<&str>,
) -> Self
pub fn with_health_check_options( self, cmd: &str, interval: Option<&str>, timeout: Option<&str>, retries: Option<u32>, start_period: Option<&str>, ) -> Self
Set a health check with custom options for the container
§Arguments
cmd- Command to run for health checkinterval- Optional time between running the check (e.g., “30s”, “1m”)timeout- Optional maximum time to wait for a check to complete (e.g., “30s”, “1m”)retries- Optional number of consecutive failures needed to consider unhealthystart_period- Optional start period for the container to initialize before counting retries (e.g., “30s”, “1m”)
§Returns
Self- The container instance for method chaining
Sourcepub fn with_snapshotter(self, snapshotter: &str) -> Self
pub fn with_snapshotter(self, snapshotter: &str) -> Self
Sourcepub fn with_detach(self, detach: bool) -> Self
pub fn with_detach(self, detach: bool) -> Self
Sourcepub fn with_runtime(self, runtime: &str) -> Self
pub fn with_runtime(self, runtime: &str) -> Self
Sourcepub fn with_disk_limit(self, size: &str) -> Self
pub fn with_disk_limit(self, size: &str) -> Self
Set disk size limit for the container
For Kata containers, this sets the VM block device size via OCI annotation. The size should be specified in a format like “10G”, “512M”, etc. The annotation will be automatically added when building if runtime is kata-related.
§Arguments
size- Disk size limit (e.g., “10G” for 10GB, “512M” for 512MB)
§Returns
Self- The container instance for method chaining
Sourcepub fn with_annotation(self, key: &str, value: &str) -> Self
pub fn with_annotation(self, key: &str, value: &str) -> Self
Sourcepub fn with_annotations(self, annotations_map: &HashMap<&str, &str>) -> Self
pub fn with_annotations(self, annotations_map: &HashMap<&str, &str>) -> Self
Sourcepub fn with_privileged(self, privileged: bool) -> Self
pub fn with_privileged(self, privileged: bool) -> Self
Sourcepub fn with_device(self, device: &str) -> Self
pub fn with_device(self, device: &str) -> Self
Sourcepub fn with_devices(self, devices: &[&str]) -> Self
pub fn with_devices(self, devices: &[&str]) -> Self
Sourcepub fn build(self) -> Result<Self, NerdctlError>
pub fn build(self) -> Result<Self, NerdctlError>
Source§impl Container
impl Container
Sourcepub fn start(&self) -> Result<CommandResult, NerdctlError>
pub fn start(&self) -> Result<CommandResult, NerdctlError>
Start the container and verify it’s running If the container hasn’t been created yet, it will be created automatically.
§Returns
Result<CommandResult, NerdctlError>- Command result or error with detailed information
Sourcepub fn stop(&self) -> Result<CommandResult, NerdctlError>
pub fn stop(&self) -> Result<CommandResult, NerdctlError>
Sourcepub fn remove(&self) -> Result<CommandResult, NerdctlError>
pub fn remove(&self) -> Result<CommandResult, NerdctlError>
Sourcepub fn exec(&self, command: &str) -> Result<CommandResult, NerdctlError>
pub fn exec(&self, command: &str) -> Result<CommandResult, NerdctlError>
Sourcepub fn copy(
&self,
source: &str,
dest: &str,
) -> Result<CommandResult, NerdctlError>
pub fn copy( &self, source: &str, dest: &str, ) -> Result<CommandResult, NerdctlError>
Sourcepub fn export(&self, path: &str) -> Result<CommandResult, NerdctlError>
pub fn export(&self, path: &str) -> Result<CommandResult, NerdctlError>
Sourcepub fn commit(&self, image_name: &str) -> Result<CommandResult, NerdctlError>
pub fn commit(&self, image_name: &str) -> Result<CommandResult, NerdctlError>
Sourcepub fn status(&self) -> Result<ContainerStatus, NerdctlError>
pub fn status(&self) -> Result<ContainerStatus, NerdctlError>
Sourcepub fn health_status(&self) -> Result<String, NerdctlError>
pub fn health_status(&self) -> Result<String, NerdctlError>
Get the health status of the container
§Returns
Result<String, NerdctlError>- Health status or error
Sourcepub fn logs(&self) -> Result<CommandResult, NerdctlError>
pub fn logs(&self) -> Result<CommandResult, NerdctlError>
Sourcepub fn resources(&self) -> Result<ResourceUsage, NerdctlError>
pub fn resources(&self) -> Result<ResourceUsage, NerdctlError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Container
impl RefUnwindSafe for Container
impl Send for Container
impl Sync for Container
impl Unpin for Container
impl UnwindSafe for Container
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more