summaryrefslogtreecommitdiffstats
path: root/examples/containercopyfrom.rs
blob: 2ebeccfce4117599738c6b9233bff47c91d5300c (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
use shiplift::Docker;
use std::{env, path};
use tokio::prelude::{Future, Stream};

fn main() {
    let docker = Docker::new();
    let id = env::args()
        .nth(1)
        .expect("Usage: cargo run --example containercopyfrom -- <container> <path in container>");
    let path = env::args()
        .nth(2)
        .expect("Usage: cargo run --example containercopyfrom -- <container> <path in container>");
    let fut = docker
        .containers()
        .get(&id)
        .copy_from(path::Path::new(&path))
        .collect()
        .and_then(|stream| {
            let tar = stream.concat();
            let mut archive = tar::Archive::new(tar.as_slice());
            archive.unpack(env::current_dir()?)?;
            Ok(())
        })
        .map_err(|e| eprintln!("Error: {}", e));
    tokio::run(fut);
}