summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMarc Schreiber <schrieveslaach@online.de>2019-02-23 20:48:17 +0100
committerdoug tangren <d.tangren@gmail.com>2019-02-23 14:48:17 -0500
commit0ae953c69ce7a336794244adc29bbc206320705d (patch)
treed32b35c42675b7ee9403a0d42659d6e4c1345943 /examples
parentebb293813fb1c92149a5cc802043ba41f4ddf1a5 (diff)
Copy a byte slice as file into a container (#151)
- add function copy_file_into to container - add example
Diffstat (limited to 'examples')
-rw-r--r--examples/containercopyinto.rs28
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);
+}