Struct podman_api::api::Containers
source · pub struct Containers { /* private fields */ }
Expand description
Handle for Podman Containers.
Implementations§
source§impl Containers
impl Containers
source§impl Containers
impl Containers
sourcepub async fn create(
&self,
opts: &ContainerCreateOpts
) -> Result<ContainerCreateCreatedBody>
pub async fn create(
&self,
opts: &ContainerCreateOpts
) -> Result<ContainerCreateCreatedBody>
Create a container with specified options.
Examples:
async {
use podman_api::Podman;
use podman_api::opts::ContainerCreateOpts;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman
.containers()
.create(
&ContainerCreateOpts::builder()
.image("debian:11")
.command(
["/usr/bin/httpd"]
)
.env([
("app", "web"),
])
.build(),
)
.await
{
eprintln!("{}", e);
}
};
sourcepub async fn list(&self, opts: &ContainerListOpts) -> Result<Vec<ListContainer>>
pub async fn list(&self, opts: &ContainerListOpts) -> Result<Vec<ListContainer>>
Returns a list of containers.
Examples:
async {
use podman_api::Podman;
use podman_api::opts::{ContainerListOpts, ContainerListFilter};
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
for container in podman
.containers()
.list(
&ContainerListOpts::builder()
.all(true)
.filter([ContainerListFilter::LabelKeyVal("app".into(), "web".into())])
.build(),
)
.await
.unwrap()
{
println!("{:?}", container);
}
};
sourcepub async fn stats(
&self,
opts: &ContainerStatsOpts
) -> Result<ContainerStats200Response>
pub async fn stats(
&self,
opts: &ContainerStatsOpts
) -> Result<ContainerStats200Response>
Return a single resource usage statistics of one or more container. If not container is specified in the options, the statistics of all are returned.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman.containers().stats(&Default::default()).await {
Ok(stats) => println!("{:?}", stats),
Err(e) => eprintln!("{}", e),
}
};
sourcepub fn stats_stream(
&self,
opts: &ContainerStatsOpts
) -> impl Stream<Item = Result<ContainerStats200Response>> + '_
pub fn stats_stream(
&self,
opts: &ContainerStatsOpts
) -> impl Stream<Item = Result<ContainerStats200Response>> + '_
Return a stream of resource usage statistics of one or more container. If not container is specified in the options, the statistics of all are returned.
Examples:
use futures_util::StreamExt;
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
let containers = podman.containers();
let mut stats = containers
.stats_stream(&Default::default());
while let Some(chunk) = stats.next().await {
match chunk {
Ok(chunk) => println!("{:?}", chunk),
Err(e) => eprintln!("{}", e),
}
}
};
sourcepub async fn list_mounted(&self) -> Result<Value>
pub async fn list_mounted(&self) -> Result<Value>
List all mounted containers mount points.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman.containers().list_mounted().await {
Ok(mounts) => println!("{:?}", mounts),
Err(e) => eprintln!("{}", e),
}
};
sourcepub async fn prune(
&self,
opts: &ContainerPruneOpts
) -> Result<Vec<ContainersPruneReportLibpod>>
pub async fn prune(
&self,
opts: &ContainerPruneOpts
) -> Result<Vec<ContainersPruneReportLibpod>>
Remove containers not in use.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman.containers().prune(&Default::default()).await {
Ok(report) => println!("{:?}", report),
Err(e) => eprintln!("{}", e),
}
};