pub trait Containers: DockerApiClient {
Show 17 methods
// Provided methods
fn get_response_from_api(
&self,
api_endpoint: &str,
method: &str,
body: &str,
) -> Result<Response, String> { ... }
fn get_containers(
&self,
api_endpoint: &str,
method: &str,
query_param: &str,
) -> Result<Vec<Container>, String> { ... }
fn list_running_containers(
&self,
limit: Option<u32>,
) -> Result<Vec<Container>, String> { ... }
fn list_all_containers(
&self,
limit: Option<u32>,
) -> Result<Vec<Container>, String> { ... }
fn get_container_details_with_filter(
&self,
filter: &str,
limit: Option<u32>,
) -> Result<Vec<Container>, String> { ... }
fn create_container(
&self,
name: &str,
config: ContainerConfig,
) -> Result<CreateContainerResponse, String> { ... }
fn create_container_minimal(
&self,
name: &str,
image: &str,
cmd: Vec<String>,
) -> Result<CreateContainerResponse, String> { ... }
fn inspect_container(&self, id: &str) -> Result<ContainerDetails, String> { ... }
fn get_container_filesystem_changes(
&self,
id: &str,
) -> Result<Vec<ContainerFsChange>, String> { ... }
fn manipulate_container_status(
&self,
action: &str,
id: &str,
params: &str,
) -> Result<String, String> { ... }
fn start_container(&self, id: &str) -> Result<String, String> { ... }
fn stop_container(
&self,
id: &str,
delay: Option<&str>,
) -> Result<String, String> { ... }
fn pause_container(&self, id: &str) -> Result<String, String> { ... }
fn unpause_container(&self, id: &str) -> Result<String, String> { ... }
fn restart_container(
&self,
id: &str,
delay: Option<&str>,
) -> Result<String, String> { ... }
fn kill_container(
&self,
id: &str,
signal: Option<&str>,
) -> Result<String, String> { ... }
fn rename_container(&self, id: &str, name: &str) -> Result<String, String> { ... }
}
Provided Methods§
Sourcefn get_response_from_api(
&self,
api_endpoint: &str,
method: &str,
body: &str,
) -> Result<Response, String>
fn get_response_from_api( &self, api_endpoint: &str, method: &str, body: &str, ) -> Result<Response, String>
Just a helper function for the Containers DockerApiClient. It formats the API request using the given parameters, and using this request the docker daemon and sends back the response of the request if the request was successful else an err.
Sourcefn get_containers(
&self,
api_endpoint: &str,
method: &str,
query_param: &str,
) -> Result<Vec<Container>, String>
fn get_containers( &self, api_endpoint: &str, method: &str, query_param: &str, ) -> Result<Vec<Container>, String>
Get Containers from the API endpoint with the method and query_param. Helper function for Container trait.
Sourcefn list_running_containers(
&self,
limit: Option<u32>,
) -> Result<Vec<Container>, String>
fn list_running_containers( &self, limit: Option<u32>, ) -> Result<Vec<Container>, String>
List all the running containers Return an instance of Vector of container
§Example
extern crate docker_rs;
use docker_rs::api::containers::Containers;
use docker_rs::client::DockerClient;
let client = match DockerClient::new("unix:///var/run/docker.sock") {
Ok(a) => a,
Err(err) => {
println!("{}", err);
std::process::exit(1);
}
};
match client.list_running_containers(None) {
Ok(containers) => println!("{:?}", containers),
Err(err) => println!("An error occured : {}", err),
}
Sourcefn list_all_containers(
&self,
limit: Option<u32>,
) -> Result<Vec<Container>, String>
fn list_all_containers( &self, limit: Option<u32>, ) -> Result<Vec<Container>, String>
List all containers whether running or stopped.
Sourcefn get_container_details_with_filter(
&self,
filter: &str,
limit: Option<u32>,
) -> Result<Vec<Container>, String>
fn get_container_details_with_filter( &self, filter: &str, limit: Option<u32>, ) -> Result<Vec<Container>, String>
List container with the filter provided, the filter can be looked from Docker engine official API documentation. https://docs.docker.com/engine/api/v1.37/#operation/ContainerList
Sourcefn create_container(
&self,
name: &str,
config: ContainerConfig,
) -> Result<CreateContainerResponse, String>
fn create_container( &self, name: &str, config: ContainerConfig, ) -> Result<CreateContainerResponse, String>
Create a container from the ContainerConfig structure with the provided
name
. The response for the request is the CreateContaierResponse struct
which contains the ID for the container which we created.
Sourcefn create_container_minimal(
&self,
name: &str,
image: &str,
cmd: Vec<String>,
) -> Result<CreateContainerResponse, String>
fn create_container_minimal( &self, name: &str, image: &str, cmd: Vec<String>, ) -> Result<CreateContainerResponse, String>
Creates/Spawn docker container from the configuration provided. It only
- Rust does not provide named arguments, so we are doing it this way Currently rust structures does not have default values, so all the values for the structure needs to be specified.
§Example
extern crate docker_rs;
use docker_rs::api::containers::Containers;
use docker_rs::client::DockerClient;
let client = match DockerClient::new("unix:///var/run/docker.sock") {
Ok(a) => a,
Err(err) => {
println!("{}", err);
std::process::exit(1);
}
};
let mut cmd: Vec<String> = Vec::new();
cmd.push("ls".to_string());
match client.create_container_minimal("my_container", "debian:jessie", cmd) {
Ok(containers) => println!("{:?}", containers),
Err(err) => println!("An error occured : {}", err),
}
Sourcefn inspect_container(&self, id: &str) -> Result<ContainerDetails, String>
fn inspect_container(&self, id: &str) -> Result<ContainerDetails, String>
Inspects the container with the provided ID Returns Low level information about the container.
§Example
extern crate docker_rs;
use docker_rs::api::containers::Containers;
use docker_rs::client::DockerClient;
let client = match DockerClient::new("unix:///var/run/docker.sock") {
Ok(a) => a,
Err(err) => {
println!("{}", err);
std::process::exit(1);
}
};
// ID of the container passed as an argument.
match client.inspect_container("f808ca...") {
Ok(info) => println!("{:?}", info),
Err(err) => println!("An error occured : {}", err),
}
Sourcefn get_container_filesystem_changes(
&self,
id: &str,
) -> Result<Vec<ContainerFsChange>, String>
fn get_container_filesystem_changes( &self, id: &str, ) -> Result<Vec<ContainerFsChange>, String>
Gives the changes done to somewhere in the filesystem in the docker container as a list of files with the kind of changes.
Sourcefn manipulate_container_status(
&self,
action: &str,
id: &str,
params: &str,
) -> Result<String, String>
fn manipulate_container_status( &self, action: &str, id: &str, params: &str, ) -> Result<String, String>
Function to manipulate container status It is a parent function for all the commands which result in a status change of the container.
This includes the following:
start_container
stop_container
pause_container
unpause_container
restart_container
kill_container
rename_container
You can call any of these function or directly manipulate_container_status
§Example
extern crate docker_rs;
use docker_rs::api::containers::Containers;
use docker_rs::client::DockerClient;
let client = match DockerClient::new("unix:///var/run/docker.sock") {
Ok(a) => a,
Err(err) => {
println!("{}", err);
std::process::exit(1);
}
};
// ID of the container passed as an argument.
match client.manipulate_container_status("start", "f808ca...", "") {
Ok(info) => println!("{:?}", info),
Err(err) => println!("An error occured : {}", err),
}
// Or alternatively you can also directly use
match client.start_container("f808ca...") {
Ok(info) => println!("{}", info),
Err(err) => println!("An error occured : {}", err),
}
// Similarly other function can also be used