diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/containercopyinto.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/containercopyinto.rs b/examples/containercopyinto.rs new file mode 100644 index 0000000..df56ca2 --- /dev/null +++ b/examples/containercopyinto.rs @@ -0,0 +1,28 @@ +use shiplift::Docker; +use std::{env, path}; +use tokio::prelude::Future; + +fn main() { + let docker = Docker::new(); + let path = env::args() + .nth(1) + .expect("Usage: cargo run --example containercopyinto -- <local path> <container>"); + let id = env::args() + .nth(2) + .expect("Usage: cargo run --example containercopyinto -- <local path> <container>"); + + + use std::fs::File; + use std::io::prelude::*; + + let mut file = File::open(&path).unwrap(); + let mut bytes = Vec::new(); + file.read_to_end(&mut bytes).expect("Cannot read file on the localhost."); + + let fut = docker + .containers() + .get(&id) + .copy_file_into(path::Path::new(&path), &bytes[..]) + .map_err(|e| eprintln!("Error: {}", e)); + tokio::run(fut); +} |