summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAndy Caldwell <andy.m.caldwell@googlemail.com>2019-02-13 05:12:42 +0000
committerdoug tangren <d.tangren@gmail.com>2019-02-13 00:12:42 -0500
commit2a40dc00e6aeb611db8095dc8646e5132fea356b (patch)
tree30929a1ee4f0386d0879054939eabd12b0a9dcda /examples
parent31a913b4a1a6a51179ddd3c3b7b6727984e829e5 (diff)
Copy from container (#150)
* Add 'copy_from' function to 'Container' * Run clippy * Update deps
Diffstat (limited to 'examples')
-rw-r--r--examples/containercopyfrom.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/containercopyfrom.rs b/examples/containercopyfrom.rs
new file mode 100644
index 0000000..2ebeccf
--- /dev/null
+++ b/examples/containercopyfrom.rs
@@ -0,0 +1,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);
+}