-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathexecinspect.rs
32 lines (24 loc) · 896 Bytes
/
execinspect.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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());
}