pub struct DockerClient { /* private fields */ }
Expand description
DockerClient
struct.
Implementations§
Source§impl DockerClient
impl DockerClient
Source§impl DockerClient
impl DockerClient
Sourcepub fn create_container(
&self,
config: Config,
) -> Result<CreatedContainer, DockerError>
pub fn create_container( &self, config: Config, ) -> Result<CreatedContainer, DockerError>
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(_) => {}
}
}
Sourcepub fn get_fs_changes<T>(&self, id: T) -> Result<Vec<FSChanges>, DockerError>
pub fn get_fs_changes<T>(&self, id: T) -> Result<Vec<FSChanges>, DockerError>
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);
}
}
Sourcepub fn start_container<T>(
&self,
id: T,
_detach_keys: T,
) -> Result<(), DockerError>
pub fn start_container<T>( &self, id: T, _detach_keys: T, ) -> Result<(), DockerError>
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),
_ => {}
}
},
}
}
Sourcepub fn stop_container<T>(
&self,
id: T,
_wait: Option<i32>,
) -> Result<(), DockerError>
pub fn stop_container<T>( &self, id: T, _wait: Option<i32>, ) -> Result<(), DockerError>
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),
_ => {}
}
},
}
}
Sourcepub fn pause_container<T>(&self, id: T) -> Result<(), DockerError>
pub fn pause_container<T>(&self, id: T) -> Result<(), DockerError>
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),
_ => {}
}
},
}
}
Sourcepub fn unpause_container<T>(&self, id: T) -> Result<(), DockerError>
pub fn unpause_container<T>(&self, id: T) -> Result<(), DockerError>
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),
_ => {}
}
},
}
}
Sourcepub fn rename_container<T>(&self, id: T, new_name: T) -> Result<(), DockerError>
pub fn rename_container<T>(&self, id: T, new_name: T) -> Result<(), DockerError>
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),
_ => {}
}
},
}
}
Sourcepub fn kill_container(&self, killer: Killer) -> Result<(), DockerError>
pub fn kill_container(&self, killer: Killer) -> Result<(), DockerError>
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),
_ => {}
}
}
}
}
Sourcepub fn remove_container(&self, remover: Remover) -> Result<(), DockerError>
pub fn remove_container(&self, remover: Remover) -> Result<(), DockerError>
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),
_ => {}
}
}
}
}
Sourcepub fn inspect_container<T>(
&self,
id: T,
size: bool,
) -> Result<ContainerInfo, DockerError>
pub fn inspect_container<T>( &self, id: T, size: bool, ) -> Result<ContainerInfo, DockerError>
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) => {},
}
}
Sourcepub fn get_container_log<T>(&self, id: T) -> Result<String, DockerError>
pub fn get_container_log<T>(&self, id: T) -> Result<String, DockerError>
Get container logs
Get stdout and stderr logs from a container.
§Note
This endpoint works only for containers with the json-file or journald logging driver.
§Arguments
id
- ID or name of the container.
§Examples
fn main() {
let client = DockerClient::connect("/var/run/docker.sock");
match client.get_container_log("test-container") {
Ok(log) => { println!("Log: {}", log); }
Err(e) => { println!("Error: {:?}", e); }
}
}
Sourcepub fn wait_container<T>(
&self,
id: T,
condition: WaitCondition,
) -> Result<WaitStatus, DockerError>
pub fn wait_container<T>( &self, id: T, condition: WaitCondition, ) -> Result<WaitStatus, DockerError>
Wait for a container
Block until a container stops, then returns the exit code.
§Arguments
id
- ID or name of the container.
condition
- Wait until a container state reaches the given condition, either ‘not-running’ (default), ‘next-exit’, or ‘removed’.
§Examples
fn main() {
let client = DockerClient::connect("/var/run/docker.sock");
match client.wait_container("test-container", WaitCondition::NotRunning) {
Ok(status) => { println!("Status: {:?}", status); }
Err(e) => { println!("Error: {:?}", e); }
}
}
Sourcepub fn export_container<T>(&self, id: T) -> Result<(), DockerError>
pub fn export_container<T>(&self, id: T) -> Result<(), DockerError>
Sourcepub fn get_image_list(&self) -> Result<Vec<ShortImageInfo>, DockerError>
pub fn get_image_list(&self) -> Result<Vec<ShortImageInfo>, DockerError>
Get images list
Return vector of ShortImageInfo or DockerError
§Examples
fn main() {
let client = DockerClient::connect("/var/run/docker.sock");
match client.get_image_list() {
Ok(list) => { println!("{:?}", list); },
Err(e) => { println!("Error: {:?}", e); },
}
}
Sourcepub fn create_volume(&self, volume: VolumeCreator) -> Result<(), DockerError>
pub fn create_volume(&self, volume: VolumeCreator) -> Result<(), DockerError>
Create a volume
Return empty object or DockerError
§Arguments
volume
- VolumeCreator struct.
§Examples
fn main() {
let client = DockerClient::connect("/var/run/docker.sock");
let creator = VolumeCreator::builder()
.name("test")
.build();
match client.create_volume(creator) {
Ok(_) => {},
Err(e) => { println!("Error: {:?}", e); },
}
}
Sourcepub fn inspect_volume<T>(&self, name: T) -> Result<VolumeInfo, DockerError>
pub fn inspect_volume<T>(&self, name: T) -> Result<VolumeInfo, DockerError>
Sourcepub fn remove_volume<T>(&self, name: T, force: bool) -> Result<(), DockerError>
pub fn remove_volume<T>(&self, name: T, force: bool) -> Result<(), DockerError>
Remove volume
Instruct the driver to remove the volume.
§Arguments
name
- ID or name of the volume.force
- Force the removal of the volume.
§Examples
fn main() {
let client = DockerClient::connect("/var/run/docker.sock");
match client.remove_volume("test", false) {
Ok(_) => {},
Err(e) => { println!("Error: {:?}", e); },
}
}
Sourcepub fn delete_unused_volumes(&self) -> Result<DeletedInfo, DockerError>
pub fn delete_unused_volumes(&self) -> Result<DeletedInfo, DockerError>
Delete unused volumes
Return empty or DockerError
§Examples
fn main() {
let client = DockerClient::connect("/var/run/docker.sock");
match client.delete_unused_volumes() {
Ok(_) => {},
Err(e) => { println!("Error: {:?}", e); },
}
}
Sourcepub fn get_volumes_list(&self) -> Result<VolumesList, DockerError>
pub fn get_volumes_list(&self) -> Result<VolumesList, DockerError>
Get volumes list
Return VolumesList or DockerError
§Examples
fn main() {
let client = DockerClient::connect("/var/run/docker.sock");
match client.get_volumes_list() {
Ok(list) => { println!("{:?}", list); },
Err(e) => { println!("Error: {:?}", e); },
}
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DockerClient
impl !RefUnwindSafe for DockerClient
impl Send for DockerClient
impl Sync for DockerClient
impl Unpin for DockerClient
impl !UnwindSafe for DockerClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more