Skip to main content

ContainerRuntime

Trait ContainerRuntime 

Source
pub trait ContainerRuntime: Send + Sync {
    // Required methods
    fn start(
        &self,
        spec: &ContainerSpec,
    ) -> impl Future<Output = Result<ContainerId>> + Send;
    fn stop(
        &self,
        id: &ContainerId,
        grace: Duration,
    ) -> impl Future<Output = Result<()>> + Send;
    fn remove(&self, name: &str) -> impl Future<Output = Result<()>> + Send;
    fn inspect(
        &self,
        id: &ContainerId,
    ) -> impl Future<Output = Result<ContainerStatus>> + Send;
    fn wait_healthy(
        &self,
        id: &ContainerId,
        timeout: Duration,
    ) -> impl Future<Output = Result<()>> + Send;
    fn logs(
        &self,
        id: &ContainerId,
        follow: bool,
    ) -> impl Future<Output = Result<LogChunkStream>> + Send;
}
Expand description

Container runtime abstraction.

The trait is intentionally narrow: it exposes only the operations that the lifecycle manager needs. Daemon-specific capabilities (network inspection, image management) stay private to each implementation.

Implementations live in submodules such as crate::DockerRuntime.

Required Methods§

Source

fn start( &self, spec: &ContainerSpec, ) -> impl Future<Output = Result<ContainerId>> + Send

Start a container according to spec. Pulls the image if not already present locally.

Source

fn stop( &self, id: &ContainerId, grace: Duration, ) -> impl Future<Output = Result<()>> + Send

Stop a container, sending SIGTERM and then SIGKILL after grace. Idempotent: stopping an already stopped container is a no-op.

Source

fn remove(&self, name: &str) -> impl Future<Output = Result<()>> + Send

Remove a container by name, forcing removal even if it is still running. Idempotent: removing a container that does not exist is a no-op. Named volumes are preserved.

The lifecycle manager calls this before every start so that a re-up or restart replaces the previous container instead of colliding with its name.

Source

fn inspect( &self, id: &ContainerId, ) -> impl Future<Output = Result<ContainerStatus>> + Send

Report the current status of a container.

Source

fn wait_healthy( &self, id: &ContainerId, timeout: Duration, ) -> impl Future<Output = Result<()>> + Send

Block until the container reports a healthy status or timeout elapses. Returns crate::RuntimeError::Timeout in the latter case.

Source

fn logs( &self, id: &ContainerId, follow: bool, ) -> impl Future<Output = Result<LogChunkStream>> + Send

Stream logs from a container. When follow is true the stream stays open and emits new chunks as they arrive; when false the stream completes after the existing logs are drained.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§