From a4cd2185976ad56b880d5a10374c4dee6d116e6a Mon Sep 17 00:00:00 2001 From: Tom Fay Date: Fri, 20 Mar 2020 01:25:54 +0000 Subject: Specify user when creating container (#220) --- src/builder.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index 0eecfa1..5541605 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -911,6 +911,14 @@ impl ContainerOptionsBuilder { self } + pub fn user( + &mut self, + user: &str, + ) -> &mut Self { + self.params.insert("User", json!(user)); + self + } + pub fn build(&self) -> ContainerOptions { ContainerOptions { name: self.name.clone(), @@ -1657,6 +1665,18 @@ mod tests { ); } + #[test] + fn container_options_user() { + let options = ContainerOptionsBuilder::new("test_image") + .user("alice") + .build(); + + assert_eq!( + r#"{"HostConfig":{},"Image":"test_image","User":"alice"}"#, + options.serialize().unwrap() + ); + } + #[test] fn container_options_host_config() { let options = ContainerOptionsBuilder::new("test_image") -- cgit v1.2.3