summaryrefslogtreecommitdiffstats
path: root/examples/execinspect.rs
diff options
context:
space:
mode:
authorWojciech Kępka <46892771+wojciechkepka@users.noreply.github.com>2021-02-06 07:57:49 +0100
committerGitHub <noreply@github.com>2021-02-06 01:57:49 -0500
commitef3dfad8f691f64e41fb1d369399471cde6ad8c0 (patch)
treee8b5bba9d148b3522171eaf72b33624334774416 /examples/execinspect.rs
parent9b85dc8a9d370139e8eb3cafadf5a0f8f6dc6597 (diff)
Add Exec struct for easier manipulation of exec instances (#251)
* Add ExecDetails and ProcessConfig * Add exec_with_id, exec_inspect * Add example how to inspect an exec instance * Make clippy happy * exit_code is an Option on ExecDetails * Add Exec struct * Update example * Fix typo * Add Exec::resize and ExecResizeOptions * Add resize example
Diffstat (limited to 'examples/execinspect.rs')
-rw-r--r--examples/execinspect.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/execinspect.rs b/examples/execinspect.rs
new file mode 100644
index 0000000..de92ec7
--- /dev/null
+++ b/examples/execinspect.rs
@@ -0,0 +1,32 @@
+use futures::StreamExt;
+use shiplift::{Docker, Exec, ExecContainerOptions};
+use std::env;
+
+#[tokio::main]
+async fn main() {
+ let docker = Docker::new();
+ let mut args = env::args().skip(1);
+
+ // First argument is container id
+ let id = args.next().expect("You need to specify a container id");
+ // Rest is command to run in the container
+ let cmd = args.collect::<Vec<String>>();
+ println!("{} {:?}", id, cmd);
+
+ // Create options with specified command
+ let opts = ExecContainerOptions::builder()
+ .cmd(cmd.iter().map(String::as_str).collect())
+ .attach_stdout(true)
+ .attach_stderr(true)
+ .build();
+
+ let exec = Exec::create(&docker, &id, &opts).await.unwrap();
+
+ println!("{:#?}", exec.inspect().await.unwrap());
+
+ let mut stream = exec.start();
+
+ stream.next().await;
+
+ println!("{:#?}", exec.inspect().await.unwrap());
+}