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;
    fn ensure_project_network(
        &self,
        project: &str,
    ) -> impl Future<Output = Result<()>> + Send;
    fn teardown_project_network(
        &self,
        project: &str,
    ) -> impl Future<Output = Result<()>> + 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.

Source

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

Ensure a per-project user-defined bridge network exists, creating it when absent. Idempotent: concurrent calls are safe because a 409 Conflict response (network already exists) is treated as success. Containers attached to this network can reach each other by their container name, enabling resources.<name>.url hostnames to resolve without extra configuration.

Source

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

Remove the per-project bridge network. Idempotent: a 404 Not Found response is treated as success. Call after all containers belonging to the project have been removed; Docker refuses to delete a network that still has active endpoints.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§