From 0ae953c69ce7a336794244adc29bbc206320705d Mon Sep 17 00:00:00 2001 From: Marc Schreiber Date: Sat, 23 Feb 2019 20:48:17 +0100 Subject: Copy a byte slice as file into a container (#151) - add function copy_file_into to container - add example --- examples/containercopyinto.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/containercopyinto.rs (limited to 'examples') 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 -- "); + let id = env::args() + .nth(2) + .expect("Usage: cargo run --example containercopyinto -- "); + + + 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); +} -- cgit v1.2.3