[][src]Struct docker_client::client::DockerClient

pub struct DockerClient { /* fields omitted */ }

DockerClient struct.

Methods

impl DockerClient[src]

pub fn connect<T>(path: T) -> DockerClient where
    T: Into<String>, 
[src]

Connect to docker

Arguments

  • sock - connection address

Examples

use docker_client::DockerClient;

fn main() {
    let client = DockerClient::connect("/var/run/docker.sock");
}

impl DockerClient[src]

pub fn create_container(
    &self,
    config: Config
) -> Result<CreatedContainer, DockerError>
[src]

Create a container

Arguments

  • Config is container to create.

Examples

use docker_client::DockerClient;
use docker_client::container::Config;

fn main() {
    let client = DockerClient::connect("/var/run/docker.sock");

    let config = Config::with_image("alpine").name("test").build();
    match client.create_container(config) {
        Ok(_) => {},
        Err(_) => {}
    }
}

pub fn get_fs_changes<T>(&self, id: T) -> Result<Vec<FSChanges>, DockerError> where
    T: Into<String>, 
[src]

Returns which files in a container's filesystem have been added, deleted, or modified.

Arguments

  • id - ID or name of the container.

Examples

use docker_client::DockerClient;

fn main() {
    let client = DockerClient::connect("/var/run/docker.sock");

    let changes = client.get_fs_changes("test").unwrap_or(Vec::new());

    for change in &changes {
        println!("{:?}", change);
    }
}

pub fn start_container<T>(
    &self,
    id: T,
    _detach_keys: T
) -> Result<(), DockerError> where
    T: Into<String>, 
[src]

Start a container.

Arguments

  • id - ID or name of the container.
  • detach_keys - The key sequence for detaching a container.

Examples

use docker_client::{DockerClient, DockerError};

fn main() {
    let client = DockerClient::connect("/var/run/docker.sock");

    match client.start_container("test", "-d") {
        Ok(_) => {},
        Err(e) => {
            match e {
                DockerError::NotFound(e) => println!("{}", e.message),
                DockerError::ServerError(e) => println!("{}", e.message),
                _ => {}
            }
        },
    }

}

pub fn stop_container<T>(
    &self,
    id: T,
    _wait: Option<i32>
) -> Result<(), DockerError> where
    T: Into<String>, 
[src]

Stop a container.

Arguments

  • id - ID or name of the container.
  • wait - Number of seconds to wait before killing the container.

Examples

use docker_client::{DockerClient, DockerError};

fn main() {
    let client = DockerClient::connect("/var/run/docker.sock");

    match client.stop_container("test", Some(12)) {
        Ok(_) => {},
        Err(e) => {
            match e {
                DockerError::NotFound(e) => println!("{}", e.message),
                DockerError::ServerError(e) => println!("{}", e.message),
                _ => {}
            }
        },
    }

}

pub fn pause_container<T>(&self, id: T) -> Result<(), DockerError> where
    T: Into<String>, 
[src]

Pause a container.

Arguments

  • id - ID or name of the container.

Examples

use docker_client::{DockerClient, DockerError};

fn main() {
    let client = DockerClient::connect("/var/run/docker.sock");

    match client.pause_container("test") {
        Ok(_) => {},
        Err(e) => {
            match e {
                DockerError::NotFound(e) => println!("{}", e.message),
                DockerError::ServerError(e) => println!("{}", e.message),
                _ => {}
            }
        },
    }

}

pub fn unpause_container<T>(&self, id: T) -> Result<(), DockerError> where
    T: Into<String>, 
[src]

Unpause a container.

Arguments

  • id - ID or name of the container.

Examples

use docker_client::{DockerClient, DockerError};

fn main() {
    let client = DockerClient::connect("/var/run/docker.sock");

    match client.unpause_container("test") {
        Ok(_) => {},
        Err(e) => {
            match e {
                DockerError::NotFound(e) => println!("{}", e.message),
                DockerError::ServerError(e) => println!("{}", e.message),
                _ => {}
            }
        },
    }

}

pub fn rename_container<T>(&self, id: T, new_name: T) -> Result<(), DockerError> where
    T: Into<String>, 
[src]

Rename a container.

Arguments

  • id - ID or name of the container.
  • new_name - New name for the container.

Examples

use docker_client::{DockerClient, DockerError};

fn main() {
    let client = DockerClient::connect("/var/run/docker.sock");

    match client.rename_container("test", "test1") {
        Ok(_) => {},
        Err(e) => {
            match e {
                DockerError::NotFound(e) => println!("{}", e.message),
                DockerError::ContainerExists(e) => println!("{}", e.message),
                DockerError::ServerError(e) => println!("{}", e.message),
                _ => {}
            }
        },
    }

}

pub fn kill_container(&self, killer: Killer) -> Result<(), DockerError>[src]

Kill a container.

Arguments

  • killer is a struct with metadata to kill a container.

Examples

use docker_client::{DockerClient, DockerError};
use docker_client::container::Killer;

fn main() {

    let client = DockerClient::connect("/var/run/docker.sock");

    let killer = Killer::new()
        .id("test")
        .build();

    match client.kill_container(killer) {
        Ok(_) => {}
        Err(e) => {
            match e {
                DockerError::NotFound(e) => println!("{}", e.message),
                DockerError::NotRunning(e) => println!("{}", e.message),
                DockerError::ServerError(e) => println!("{}", e.message),
                _ => {}
            }
        }
    }

}

pub fn remove_container(&self, remover: Remover) -> Result<(), DockerError>[src]

Remove a container.

Arguments

  • remover is a struct with metadata to remove a container.

Examples

use docker_client::{DockerClient, DockerError};
use docker_client::container::Remover;

fn main() {

    let client = DockerClient::connect("/var/run/docker.sock");

    let remover = Remover::new()
        .id("test")
        .with_remove_volumes(true)
        .build();

    match client.remove_container(remover) {
        Ok(_) => {}
        Err(e) => {
            match e {
                DockerError::BadParameters(e) => println!("{}", e.message),
                DockerError::NotFound(e) => println!("{}", e.message),
                DockerError::NotRunning(e) => println!("{}", e.message),
                DockerError::ServerError(e) => println!("{}", e.message),
                _ => {}
            }
        }
    }

}

pub fn inspect_container<T>(
    &self,
    id: T,
    size: bool
) -> Result<ContainerInfo, DockerError> where
    T: Into<String>, 
[src]

Inspect a container.

Return ContainerInfo structure about a container.

Arguments

  • id - ID or name of the container.
  • size - Return the size of container as fields SizeRw and SizeRootFs.

Examples

use docker_client::{DockerClient, DockerError};

fn main() {
    let client = DockerClient::connect("/var/run/docker.sock");

    match client.inspect_container("test", true) {
        Ok(s) => { println!("{:?}", s) },
        Err(e) => {},
    }

}

Trait Implementations

impl Debug for DockerClient[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]