summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/containerexec.rs14
-rw-r--r--src/builder.rs9
2 files changed, 18 insertions, 5 deletions
diff --git a/examples/containerexec.rs b/examples/containerexec.rs
index 25475da..fe542f2 100644
--- a/examples/containerexec.rs
+++ b/examples/containerexec.rs
@@ -5,12 +5,16 @@ use std::env;
fn main() {
let docker = Docker::new();
- let options = ExecContainerOptions::builder().cmd(vec!["ls"]).build();
+ let options = ExecContainerOptions::builder()
+ .cmd(vec!["ls"])
+ .env(vec!["VAR=value"])
+ .build();
if let Some(id) = env::args().nth(1) {
- let container = docker.containers()
+ match docker.containers()
.get(&id)
- .exec(&options)
- .unwrap();
- println!("{:?}", container);
+ .exec(&options) {
+ Ok(res) => println!("Success: {:?}", res),
+ Err(err) => println!("An error occured: {:?}", err),
+ }
}
}
diff --git a/src/builder.rs b/src/builder.rs
index 4b80e57..c13dca6 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -458,6 +458,7 @@ impl ExecContainerOptionsBuilder {
ExecContainerOptionsBuilder { params: HashMap::new() }
}
+ /// Command to run, as an array of strings
pub fn cmd(&mut self, cmds: Vec<&str>) -> &mut ExecContainerOptionsBuilder {
for cmd in cmds {
self.params.entry("Cmd").or_insert(Vec::new()).push(cmd.to_owned());
@@ -465,6 +466,14 @@ impl ExecContainerOptionsBuilder {
self
}
+ /// A list of environment variables in the form "VAR=value"
+ pub fn env(&mut self, envs: Vec<&str>) -> &mut ExecContainerOptionsBuilder {
+ for env in envs {
+ self.params.entry("Env").or_insert(Vec::new()).push(env.to_owned());
+ }
+ self
+ }
+
pub fn build(&self) -> ExecContainerOptions {
ExecContainerOptions { params: self.params.clone() }
}