summaryrefslogtreecommitdiffstats
path: root/examples/export.rs
blob: 55d1b7b590480b425ffd94265af3885efbe8c27e (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
use shiplift::{errors::Error, Docker};
use std::{env, fs::OpenOptions, io::Write};
use tokio::prelude::{Future, Stream};

fn main() {
    let docker = Docker::new();
    let id = env::args().nth(1).expect("You need to specify an image id");

    let mut export_file = OpenOptions::new()
        .write(true)
        .create(true)
        .open(format!("{}.tar", &id))
        .unwrap();
    let images = docker.images();
    let fut = images
        .get(&id)
        .export()
        .for_each(move |bytes| {
            export_file
                .write(&bytes[..])
                .map(|n| println!("copied {} bytes", n))
                .map_err(Error::IO)
        })
        .map_err(|e| eprintln!("Error: {}", e));

    tokio::run(fut)
}