Struct podman_api::api::Container
source · [−]pub struct Container<'podman> { /* private fields */ }
Expand description
Interface for accessing and manipulating Podman Container.
Implementations
sourceimpl<'podman> Container<'podman>
impl<'podman> Container<'podman>
sourcepub async fn start(&self, detach_keys: Option<String>) -> Result<()>
pub async fn start(&self, detach_keys: Option<String>) -> Result<()>
Start this container.
Parameters:
- detach_keys - Override the key sequence for detaching a container. Format is a single character [a-Z] or ctrl- where is one of: a-z, @, ^, [, , or _.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").start(None).await {
eprintln!("{}", e);
}
};
sourcepub async fn stop(&self, opts: &ContainerStopOpts) -> Result<()>
pub async fn stop(&self, opts: &ContainerStopOpts) -> Result<()>
Stop this container.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").stop(&Default::default()).await {
eprintln!("{}", e);
}
};
sourcepub async fn inspect(&self) -> Result<LibpodContainerInspectResponse>
pub async fn inspect(&self) -> Result<LibpodContainerInspectResponse>
Return low-level information about this container.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman.containers().get("79c93f220e3e").inspect().await {
Ok(info) => println!("{:?}", info),
Err(e) => eprintln!("{}", e),
}
};
sourcepub async fn send_signal(&self, signal: impl Into<String>) -> Result<()>
pub async fn send_signal(&self, signal: impl Into<String>) -> Result<()>
Send a signal to this container.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").send_signal("INT").await {
eprintln!("{}", e);
}
};
sourcepub async fn kill(&self) -> Result<()>
pub async fn kill(&self) -> Result<()>
Kill this container.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").kill().await {
eprintln!("{}", e);
}
};
sourcepub async fn pause(&self) -> Result<()>
pub async fn pause(&self) -> Result<()>
Use the cgroups freezer to suspend all processes in this container.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").pause().await {
eprintln!("{}", e);
}
};
sourcepub async fn unpause(&self) -> Result<()>
pub async fn unpause(&self) -> Result<()>
Unpause this container
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").unpause().await {
eprintln!("{}", e);
}
};
sourcepub async fn restart_with_timeout(&self, t: usize) -> Result<()>
pub async fn restart_with_timeout(&self, t: usize) -> Result<()>
Restart this container with a timeout.
Parameters:
- t - number of seconds to wait before killing the container
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").restart_with_timeout(20).await {
eprintln!("{}", e);
}
};
sourcepub async fn restart(&self) -> Result<()>
pub async fn restart(&self) -> Result<()>
Restart this container.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").restart().await {
eprintln!("{}", e);
}
};
sourcepub async fn delete(&self, opts: &ContainerDeleteOpts) -> Result<()>
pub async fn delete(&self, opts: &ContainerDeleteOpts) -> Result<()>
Delete this container.
Examples:
async {
use podman_api::Podman;
use podman_api::opts::ContainerDeleteOpts;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman
.containers()
.get("79c93f220e3e")
.delete(&ContainerDeleteOpts::builder().volumes(true).build())
.await
{
eprintln!("{}", e);
}
};
sourcepub async fn remove(&self) -> Result<()>
pub async fn remove(&self) -> Result<()>
Force remove this container.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").remove().await {
eprintln!("{}", e);
}
};
sourcepub async fn mount(&self) -> Result<Id>
pub async fn mount(&self) -> Result<Id>
Mount this container to the filesystem.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman.containers().get("79c93f220e3e").mount().await {
Ok(id) => println!("mounted container {}", id),
Err(e) => eprintln!("{}", e),
}
};
sourcepub async fn unmount(&self) -> Result<()>
pub async fn unmount(&self) -> Result<()>
Unmount this container from the filesystem.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").unmount().await {
eprintln!("{}", e);
}
};
sourcepub fn checkpoint(
&self,
opts: &ContainerCheckpointOpts
) -> impl Stream<Item = Result<Vec<u8>>> + Unpin + 'podman
pub fn checkpoint(
&self,
opts: &ContainerCheckpointOpts
) -> impl Stream<Item = Result<Vec<u8>>> + Unpin + 'podman
Checkpoint this container.
Examples:
use futures_util::StreamExt;
async {
use podman_api::Podman;
use podman_api::opts::ContainerCheckpointOpts;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
let mut container_stream = podman.containers().get("79c93f220e3e").checkpoint(
&ContainerCheckpointOpts::builder()
.leave_running(true)
.print_stats(true)
.build(),
);
while let Some(chunk) = container_stream.next().await {
println!("{:?}", chunk);
}
};
sourcepub async fn commit(&self, opts: &ContainerCommitOpts) -> Result<()>
pub async fn commit(&self, opts: &ContainerCommitOpts) -> Result<()>
Create a new image from this container.
Examples:
async {
use podman_api::Podman;
use podman_api::opts::ContainerCommitOpts;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman
.containers()
.get("79c93f220e3e")
.commit(
&ContainerCommitOpts::builder()
.pause(true)
.repo("image-name")
.tag("1.0.0")
.build(),
)
.await
{
eprintln!("{}", e);
}
};
sourcepub async fn create_exec(&self, opts: &ExecCreateOpts) -> Result<Exec<'_>>
pub async fn create_exec(&self, opts: &ExecCreateOpts) -> Result<Exec<'_>>
Create an exec session to run a command inside this container. Exec sessions will be automatically removed 5 minutes after they exit.
This endpoint only creates the exec. To start it use Exec::start.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
let exec = podman
.containers()
.get("79c93f220e3e")
.create_exec(
&podman_api::opts::ExecCreateOpts::builder()
.command(["cat", "/some/path/in/container"])
.attach_stdout(true)
.attach_stderr(true)
.build(),
)
.await
.unwrap();
};
sourcepub async fn rename(&self, new_name: impl AsRef<str>) -> Result<()>
pub async fn rename(&self, new_name: impl AsRef<str>) -> Result<()>
Change the name of this container.
Parameters:
- new_name - new name to give for this container
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").rename("my-container").await {
eprintln!("{}", e);
}
};
sourcepub async fn init(&self) -> Result<()>
pub async fn init(&self) -> Result<()>
Performs all tasks necessary for initializing the container but does not start the container.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("79c93f220e3e").init().await {
eprintln!("{}", e);
}
};
sourcepub async fn wait(&self, opts: &ContainerWaitOpts) -> Result<()>
pub async fn wait(&self, opts: &ContainerWaitOpts) -> Result<()>
Wait for this container to meet a given condition.
Examples:
async {
use podman_api::Podman;
use podman_api::opts::ContainerWaitOpts;
use podman_api::models::ContainerStatus;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman
.containers()
.get("79c93f220e3e")
.wait(
&ContainerWaitOpts::builder()
.conditions([ContainerStatus::Configured])
.interval("300ms")
.build(),
)
.await
{
eprintln!("{}", e);
}
};
sourcepub async fn exists(&self) -> Result<bool>
pub async fn exists(&self) -> Result<bool>
Quick way to determine if a container exists by name or ID
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman.containers().get("79c93f220e3e").exists().await {
Ok(exists) => if exists {
println!("container exists!");
} else {
println!("container doesn't exists!");
},
Err(e) => eprintln!("check failed: {}", e),
}
};
sourcepub async fn attach(
&self,
opts: &ContainerAttachOpts
) -> Result<Multiplexer<'podman>>
pub async fn attach(
&self,
opts: &ContainerAttachOpts
) -> Result<Multiplexer<'podman>>
Attach to this container.
Examples:
use futures_util::StreamExt;
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
let tty_multiplexer = podman
.containers()
.get("79c93f220e3e")
.attach(&Default::default())
.await
.unwrap();
let (mut reader, _writer) = tty_multiplexer.split();
while let Some(tty_result) = reader.next().await {
match tty_result {
Ok(chunk) => println!("{:?}", chunk),
Err(e) => eprintln!("Error: {}", e),
}
}
};
sourcepub async fn changes(
&self,
opts: &ChangesOpts
) -> Result<Vec<ContainerChangeResponseItem>>
pub async fn changes(
&self,
opts: &ChangesOpts
) -> Result<Vec<ContainerChangeResponseItem>>
Returns which files in this container’s filesystem have been added, deleted, or modified.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman
.containers()
.get("79c93f220e3e")
.changes(&Default::default())
.await
{
Ok(changes) => println!("{:?}", changes),
Err(e) => eprintln!("{}", e),
}
};
sourcepub fn logs(
&self,
opts: &ContainerLogsOpts
) -> impl Stream<Item = Result<Vec<u8>>> + 'podman
pub fn logs(
&self,
opts: &ContainerLogsOpts
) -> impl Stream<Item = Result<Vec<u8>>> + 'podman
Get logs from this container.
Examples:
use futures_util::StreamExt;
async {
use podman_api::Podman;
use podman_api::opts::ContainerLogsOpts;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
let mut logs = podman.containers().get("3f278d2d0d79").logs(
&ContainerLogsOpts::builder()
.stdout(true)
.stderr(true)
.follow(true)
.build(),
);
while let Some(chunk) = logs.next().await {
match chunk {
Ok(chunk) => println!("{}", String::from_utf8_lossy(&chunk)),
Err(e) => eprintln!("{}", e),
}
}
};
sourcepub async fn stats(&self) -> Result<LibpodContainerStatsResponse>
pub async fn stats(&self) -> Result<LibpodContainerStatsResponse>
Return a single resource usage statistics of this container.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman.containers().get("fc93f220e3e").stats().await {
Ok(stats) => println!("{:?}", stats),
Err(e) => eprintln!("{}", e),
}
};
sourcepub fn stats_stream(
&self,
interval: Option<usize>
) -> impl Stream<Item = Result<LibpodContainerStatsResponse>> + 'podman
pub fn stats_stream(
&self,
interval: Option<usize>
) -> impl Stream<Item = Result<LibpodContainerStatsResponse>> + 'podman
Return a stream of resource usage statistics of this container.
Examples:
use futures_util::StreamExt;
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
let mut stats = podman
.containers()
.get("fc93f220e3e")
.stats_stream(None);
while let Some(chunk) = stats.next().await {
match chunk {
Ok(chunk) => println!("{:?}", chunk),
Err(e) => eprintln!("{}", e),
}
}
};
sourcepub async fn top(&self, opts: &ContainerTopOpts) -> Result<ContainerTopOkBody>
pub async fn top(&self, opts: &ContainerTopOpts) -> Result<ContainerTopOkBody>
List processes running inside this container.
Examples:
async {
use podman_api::Podman;
};
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman.containers().get("fc93f220e3e").top(&Default::default()).await {
Ok(stats) => println!("{:?}", stats),
Err(e) => eprintln!("{}", e),
}
};
sourcepub fn top_stream(
&self,
opts: &ContainerTopOpts
) -> impl Stream<Item = Result<ContainerTopOkBody>> + 'podman
pub fn top_stream(
&self,
opts: &ContainerTopOpts
) -> impl Stream<Item = Result<ContainerTopOkBody>> + 'podman
List processes running inside this container as a stream. (As of libpod version 4.0)
Examples:
use futures_util::StreamExt;
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
let mut top = podman
.containers()
.get("fc93f220e3e")
.top_stream(&Default::default());
while let Some(chunk) = top.next().await {
match chunk {
Ok(chunk) => println!("{:?}", chunk),
Err(e) => eprintln!("{}", e),
}
}
};
sourcepub async fn generate_systemd_units(
&self,
opts: &SystemdUnitsOpts
) -> Result<Value>
pub async fn generate_systemd_units(
&self,
opts: &SystemdUnitsOpts
) -> Result<Value>
Generate Systemd Units based on this container.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman
.containers()
.get("fc93f220e3e")
.generate_systemd_units(&Default::default())
.await
{
Ok(info) => println!("{:?}", info),
Err(e) => eprintln!("{}", e),
}
};
sourcepub async fn generate_kube_yaml(&self, service: bool) -> Result<String>
pub async fn generate_kube_yaml(&self, service: bool) -> Result<String>
Generate Kubernetes YAML based on this container
Parameters:
- service - Generate YAML for a Kubernetes service object.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman
.containers()
.get("fc93f220e3e")
.generate_kube_yaml(false)
.await
{
Ok(yaml) => println!("{:?}", yaml),
Err(e) => eprintln!("{}", e),
}
};
sourcepub async fn connect(
&self,
network: impl Into<Id>,
opts: &NetworkConnectOpts
) -> Result<()>
pub async fn connect(
&self,
network: impl Into<Id>,
opts: &NetworkConnectOpts
) -> Result<()>
Connect this container to a network
Examples:
async {
use podman_api::Podman;
use podman_api::opts::NetworkConnectOpts;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman
.containers()
.get("fc93f220e3e")
.connect("my-network", &Default::default())
.await
{
eprintln!("{}", e);
}
};
sourcepub async fn disconnect(
&self,
network: impl Into<Id>,
force: bool
) -> Result<()>
pub async fn disconnect(
&self,
network: impl Into<Id>,
force: bool
) -> Result<()>
Disconnect this container from a network.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
if let Err(e) = podman.containers().get("fc93f220e3e").disconnect("my-network", true).await {
eprintln!("{}", e);
}
};
sourcepub async fn healtcheck(&self) -> Result<HealthCheckResults>
pub async fn healtcheck(&self) -> Result<HealthCheckResults>
Execute the defined healtcheck and return information about the result.
Examples:
async {
use podman_api::Podman;
let podman = Podman::unix("/run/user/1000/podman/podman.sock");
match podman.containers().get("fc93f220e3e").healtcheck().await {
Ok(healtcheck) => println!("{:?}", healtcheck),
Err(e) => eprintln!("{}", e),
}
};
Trait Implementations
Auto Trait Implementations
impl<'podman> !RefUnwindSafe for Container<'podman>
impl<'podman> Send for Container<'podman>
impl<'podman> Sync for Container<'podman>
impl<'podman> Unpin for Container<'podman>
impl<'podman> !UnwindSafe for Container<'podman>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more