summaryrefslogtreecommitdiffstats
path: root/examples/containerexec.rs
blob: e10d245609c8d1d49fd6717e14342d34c5da8ce2 (plain)
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
extern crate shiplift;

use shiplift::{Docker, ExecContainerOptions};
use std::env;

fn main() {
    let docker = Docker::new();
    let options = ExecContainerOptions::builder()
        .cmd(vec![
            "bash",
            "-c",
            "echo -n \"echo VAR=$VAR on stdout\"; echo -n \"echo VAR=$VAR on stderr\" >&2",
        ])
        .env(vec!["VAR=value"])
        .attach_stdout(true)
        .attach_stderr(true)
        .build();
    if let Some(id) = env::args().nth(1) {
        match docker.containers().get(&id).exec(&options) {
            Ok(res) => {
                println!("Stdout: {}", res.stdout);
                println!("Stderr: {}", res.stderr);
            }
            Err(err) => println!("An error occured: {:?}", err),
        }
    }
}