summaryrefslogtreecommitdiffstats
path: root/src/container.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/container.rs')
-rw-r--r--src/container.rs72
1 files changed, 43 insertions, 29 deletions
diff --git a/src/container.rs b/src/container.rs
index cc8d288..0fce8c1 100644
--- a/src/container.rs
+++ b/src/container.rs
@@ -20,7 +20,7 @@ use crate::{
errors::{Error, Result},
exec::{Exec, ExecContainerOptions},
image::Config,
- network::{NetworkInfo, NetworkSettings},
+ network::NetworkSettings,
transport::Payload,
tty::{self, Multiplexer as TtyMultiPlexer},
};
@@ -32,7 +32,7 @@ use chrono::{DateTime, Utc};
/// Interface for accessing and manipulating a docker container
///
-/// Api Reference: <https://docs.docker.com/engine/api/v1.41/#tag/Container>
+/// [Api Reference](https://docs.docker.com/engine/api/v1.41/#tag/Container)
pub struct Container<'docker> {
docker: &'docker Docker,
id: String,
@@ -60,7 +60,7 @@ impl<'docker> Container<'docker> {
/// Inspects the current docker container instance's details
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerInspect>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerInspect)
pub async fn inspect(&self) -> Result<ContainerDetails> {
self.docker
.get_json::<ContainerDetails>(&format!("/containers/{}/json", self.id)[..])
@@ -69,7 +69,7 @@ impl<'docker> Container<'docker> {
/// Returns a `top` view of information about the container process
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerTop>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerTop)
pub async fn top(
&self,
psargs: Option<&str>,
@@ -86,7 +86,7 @@ impl<'docker> Container<'docker> {
/// Returns a stream of logs emitted but the container instance
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerLogs>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerLogs)
pub fn logs(
&self,
opts: &LogsOptions,
@@ -114,13 +114,15 @@ impl<'docker> Container<'docker> {
.await
}
- /// Attaches a `[TtyMultiplexer]` to the container.
+ /// Attaches a [Multiplexer](crate::tty::Multiplexer) to the container.
///
- /// The `[TtyMultiplexer]` implements Stream for returning Stdout and Stderr chunks. It also implements `[AsyncWrite]` for writing to Stdin.
+ /// The [Multiplexer](crate::tty::Multiplexer) implements Stream for returning Stdout and
+ /// Stderr chunks. It also implements `[AsyncWrite]` for writing to Stdin.
///
- /// The multiplexer can be split into its read and write halves with the `[split](TtyMultiplexer::split)` method
+ /// The multiplexer can be split into its read and write halves with the
+ /// [split](crate::tty::Multiplexer::split) method
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerAttach>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerAttach)
pub async fn attach(&self) -> Result<TtyMultiPlexer<'docker>> {
let tcp_stream = self.attach_raw().await?;
@@ -129,7 +131,7 @@ impl<'docker> Container<'docker> {
/// Returns a set of changes made to the container instance
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerChanges>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerChanges)
pub async fn changes(&self) -> Result<Vec<Change>> {
self.docker
.get_json::<Vec<Change>>(&format!("/containers/{}/changes", self.id)[..])
@@ -138,7 +140,7 @@ impl<'docker> Container<'docker> {
/// Exports the current docker container into a tarball
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerExport>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerExport)
pub fn export(&self) -> impl Stream<Item = Result<Vec<u8>>> + 'docker {
self.docker
.stream_get(format!("/containers/{}/export", self.id))
@@ -147,7 +149,7 @@ impl<'docker> Container<'docker> {
/// Returns a stream of stats specific to this container instance
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerStats>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerStats)
pub fn stats(&self) -> impl Stream<Item = Result<Stats>> + Unpin + 'docker {
let codec = futures_codec::LinesCodec {};
@@ -169,7 +171,7 @@ impl<'docker> Container<'docker> {
/// Start the container instance
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerStart>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerStart)
pub async fn start(&self) -> Result<()> {
self.docker
.post(&format!("/containers/{}/start", self.id)[..], None)
@@ -179,7 +181,7 @@ impl<'docker> Container<'docker> {
/// Stop the container instance
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerStop>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerStop)
pub async fn stop(
&self,
wait: Option<Duration>,
@@ -198,7 +200,7 @@ impl<'docker> Container<'docker> {
/// Restart the container instance
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerRestart>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerRestart)
pub async fn restart(
&self,
wait: Option<Duration>,
@@ -216,7 +218,7 @@ impl<'docker> Container<'docker> {
/// Kill the container instance
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerKill>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerKill)
pub async fn kill(
&self,
signal: Option<&str>,
@@ -234,7 +236,7 @@ impl<'docker> Container<'docker> {
/// Rename the container instance
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerRename>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerRename)
pub async fn rename(
&self,
name: &str,
@@ -253,7 +255,7 @@ impl<'docker> Container<'docker> {
/// Pause the container instance
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerPause>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerPause)
pub async fn pause(&self) -> Result<()> {
self.docker
.post(&format!("/containers/{}/pause", self.id)[..], None)
@@ -263,7 +265,7 @@ impl<'docker> Container<'docker> {
/// Unpause the container instance
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerUnpause>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerUnpause)
pub async fn unpause(&self) -> Result<()> {
self.docker
.post(&format!("/containers/{}/unpause", self.id)[..], None)
@@ -273,7 +275,7 @@ impl<'docker> Container<'docker> {
/// Wait until the container stops
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerWait>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerWait)
pub async fn wait(&self) -> Result<Exit> {
self.docker
.post_json(format!("/containers/{}/wait", self.id), Payload::None)
@@ -284,7 +286,7 @@ impl<'docker> Container<'docker> {
///
/// Use remove instead to use the force/v options.
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerDelete>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerDelete)
pub async fn delete(&self) -> Result<()> {
self.docker
.delete(&format!("/containers/{}", self.id)[..])
@@ -294,7 +296,7 @@ impl<'docker> Container<'docker> {
/// Delete the container instance (todo: force/v)
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerRemove>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerRemove)
pub async fn remove(
&self,
opts: RmContainerOptions,
@@ -309,7 +311,7 @@ impl<'docker> Container<'docker> {
/// Execute a command in this container
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#tag/Exec>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#tag/Exec)
pub fn exec(
&self,
opts: &ExecContainerOptions,
@@ -326,7 +328,7 @@ impl<'docker> Container<'docker> {
/// ends in `/.` then this indicates that only the contents of the path directory should be
/// copied. A symlink is always resolved to its target.
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerArchive>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerArchive)
pub fn copy_from(
&self,
path: &Path,
@@ -344,7 +346,7 @@ impl<'docker> Container<'docker> {
/// The file will be copied at the given location (see `path`) and will be owned by root
/// with access mask 644.
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/PutContainerArchive>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/PutContainerArchive)
pub async fn copy_file_into<P: AsRef<Path>>(
&self,
path: P,
@@ -375,7 +377,7 @@ impl<'docker> Container<'docker> {
///
/// The tarball will be copied to the container and extracted at the given location (see `path`).
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/PutContainerArchive>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/PutContainerArchive)
pub async fn copy_to(
&self,
path: &Path,
@@ -399,7 +401,7 @@ impl<'docker> Container<'docker> {
/// Interface for docker containers
///
-/// Api Reference: <https://docs.docker.com/engine/api/v1.41/#tag/Containers>
+/// [Api Reference](https://docs.docker.com/engine/api/v1.41/#tag/Containers)
pub struct Containers<'docker> {
docker: &'docker Docker,
}
@@ -412,7 +414,7 @@ impl<'docker> Containers<'docker> {
/// Lists the container instances on the docker host
///
- /// Api Reference: <https://docs.docker.com/engine/api/v1.41/#operation/ContainerList>
+ /// [Api Reference](https://docs.docker.com/engine/api/v1.41/#operation/ContainerList)
pub async fn list(
&self,
opts: &ContainerListOptions,
@@ -1290,13 +1292,25 @@ pub struct Port {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Stats {
pub read: String,
- pub networks: HashMap<String, NetworkInfo>,
+ pub networks: HashMap<String, NetworkStats>,
pub memory_stats: MemoryStats,
pub blkio_stats: BlkioStats,
pub cpu_stats: CpuStats,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct NetworkStats {
+ pub rx_dropped: u64,
+ pub rx_bytes: u64,
+ pub rx_errors: u64,
+ pub tx_packets: u64,
+ pub tx_dropped: u64,
+ pub rx_packets: u64,
+ pub tx_errors: u64,
+ pub tx_bytes: u64,
+}
+
+#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MemoryStats {
pub max_usage: u64,
pub usage: u64,