Skip to main content

DockerCliRunner

Struct DockerCliRunner 

Source
pub struct DockerCliRunner { /* private fields */ }
Expand description

Docker CLI runner bound to a Unix socket.

Implementations§

Source§

impl DockerCliRunner

Source

pub fn new(socket_path: impl Into<PathBuf>) -> Result<Self>

Creates a new CLI runner for the provided Docker socket.

§Errors

Returns an error if the docker binary cannot be located.

Source

pub fn socket_path(&self) -> &Path

Returns the socket path used by this runner.

Source

pub const fn helper_image_reference(&self) -> &'static str

Returns the helper image reference used for temporary volume containers.

Source

pub async fn info(&self) -> Result<DockerInfo>

Returns Docker daemon info.

Source

pub async fn list_images(&self) -> Result<Vec<ImageInspect>>

Returns all image inspect payloads.

Source

pub async fn list_volumes(&self) -> Result<Vec<VolumeInspect>>

Returns all volume inspect payloads.

Source

pub async fn list_networks(&self) -> Result<Vec<NetworkInspect>>

Returns all user-defined network inspect payloads.

Source

pub async fn list_containers(&self) -> Result<Vec<ContainerInspect>>

Returns all container inspect payloads, including stopped containers.

Source

pub async fn stop_container(&self, id: &str) -> Result<()>

Stops a container.

Source

pub async fn start_container(&self, id: &str) -> Result<()>

Starts a container.

Source

pub async fn remove_container(&self, id: &str) -> Result<()>

Removes a container forcibly.

Source

pub async fn remove_stale_helper(&self, name: &str) -> Result<()>

Clears a helper container left behind by an interrupted run.

A run whose daemon died mid-copy strands its helper, and docker create --name refuses a duplicate — which would wedge the retry the user is certain to attempt, since a failed migration leaves them no other way to get their data across. Clearing the name first makes the volume copy idempotent.

Existence is checked rather than the removal being forced blindly, so a genuine removal failure still surfaces instead of being swallowed as “nothing was there”. remove_container passes --volumes, which reaps only anonymous volumes, so the named volume being migrated is never at risk.

Source

pub async fn remove_volume(&self, name: &str) -> Result<()>

Removes a volume.

Source

pub async fn remove_network(&self, name: &str) -> Result<()>

Removes a network.

Source

pub async fn create_volume( &self, name: &str, labels: &[(String, String)], options: &[(String, String)], ) -> Result<()>

Creates a volume with labels and options.

Source

pub async fn create_network( &self, name: &str, config: &CreateNetworkOptions, ) -> Result<()>

Creates a network using supported bridge-network flags.

Source

pub async fn create_container<I, S>(&self, args: I) -> Result<String>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Creates a container and returns its ID.

Source

pub async fn connect_network( &self, network: &str, container: &str, aliases: &[String], ) -> Result<()>

Connects a container to an additional network.

Source

pub async fn create_helper_container( &self, name: &str, volume_name: &str, ) -> Result<String>

Creates a helper container mounting the provided volume at /volume.

Source

pub async fn ensure_helper_image(&self) -> Result<()>

Ensures the helper image exists by importing an empty tar archive when needed.

Source

pub async fn pipe_save_into( &self, target: &Self, references: &[String], ) -> Result<ImageTransfer>

Streams docker save on this daemon straight into docker load on target.

references must list every tag to preserve: docker save keeps all tags of an image only for arguments given without a tag, so naming a single repo:tag silently drops that image’s other tags.

Source

pub async fn copy_from_container( &self, container: &str, source_path: &str, ) -> Result<NamedTempFile>

Streams a container path into a tempfile via docker cp.

--archive asks for source ownership explicitly. Note it is belt and braces here, not a fix: the - stream forms already round-trip uid/gid (measured 2026-08-01 — a 1000:1000 volume file survived a migration on a build without this flag). The documented “ownership is set at the destination” rule applies to path-to-path copies, not to tar streams.

Source

pub async fn copy_to_container( &self, source_archive: &Path, container: &str, target_path: &str, ) -> Result<()>

Streams a tar archive tempfile into a container via docker cp.

See Self::copy_from_container for what --archive does and does not buy here.

Trait Implementations§

Source§

impl Clone for DockerCliRunner

Source§

fn clone(&self) -> DockerCliRunner

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DockerCliRunner

Source§

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

Formats the value using the given formatter. 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, 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> 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.