DockerClient

Struct DockerClient 

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

Main Docker client for managing containers, images, networks, and volumes.

Implementations§

Source§

impl DockerClient

Source

pub fn new() -> Result<Self>

Create a new Docker client with default configuration.

This respects the DOCKER_HOST environment variable.

§Errors

Returns an error if unable to connect to the Docker daemon.

§Example
use docker_client::DockerClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DockerClient::new()?;
    Ok(())
}
Source

pub fn with_config(config: DockerClientConfig) -> Result<Self>

Create a new Docker client with custom configuration.

§Errors

Returns an error if unable to connect to the Docker daemon.

§Example
use docker_client::{DockerClient, DockerClientConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = DockerClientConfig::new()
        .timeout(60)
        .api_version("1.43");
    let client = DockerClient::with_config(config)?;
    Ok(())
}
Source

pub fn connect_with_unix(path: impl Into<PathBuf>) -> Result<Self>

Connect to Docker daemon using Unix socket.

§Example
use docker_client::DockerClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DockerClient::connect_with_unix("/var/run/docker.sock")?;
    Ok(())
}
Source

pub fn connect_with_tcp(addr: impl Into<String>) -> Result<Self>

Connect to Docker daemon using TCP.

§Example
use docker_client::DockerClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DockerClient::connect_with_tcp("localhost:2375")?;
    Ok(())
}
Source

pub async fn version(&self) -> Result<String>

Check if Docker daemon is accessible and get version info.

§Example
use docker_client::DockerClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DockerClient::new()?;
    let version = client.version().await?;
    println!("Docker version: {}", version);
    Ok(())
}
Source

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

Ping the Docker daemon to check connectivity.

§Example
use docker_client::DockerClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DockerClient::new()?;
    client.ping().await?;
    println!("Docker daemon is accessible");
    Ok(())
}
Source

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

Get system information from Docker daemon.

Source

pub fn inner(&self) -> &Docker

Access the underlying Bollard Docker client for advanced operations.

Source

pub fn registry(&self) -> Registry<'_>

Access registry operations.

Source§

impl DockerClient

Source

pub fn containers(&self) -> Containers<'_>

Access container operations.

§Example
use docker_client::DockerClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DockerClient::new()?;
    let containers = client.containers().list(true).await?;
    Ok(())
}
Source§

impl DockerClient

Source

pub fn images(&self) -> Images<'_>

Access image operations.

§Example
use docker_client::DockerClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DockerClient::new()?;
    let images = client.images().list(false).await?;
    Ok(())
}
Source§

impl DockerClient

Source

pub fn networks(&self) -> Networks<'_>

Access network operations.

§Example
use docker_client::DockerClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DockerClient::new()?;
    let networks = client.networks().list().await?;
    Ok(())
}
Source§

impl DockerClient

Source

pub fn volumes(&self) -> Volumes<'_>

Access volume operations.

§Example
use docker_client::DockerClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DockerClient::new()?;
    let volumes = client.volumes().list().await?;
    Ok(())
}

Trait Implementations§

Source§

impl Default for DockerClient

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more