From 1718105d19c53e817de9776011daacb17f6ac275 Mon Sep 17 00:00:00 2001 From: Tyler Jones Date: Thu, 26 Dec 2019 20:16:26 -0700 Subject: Update the ContainerOptionsBuilder with new publish all ports option (#215) The following change is to provide the configuration option `PublishAllPorts` which will map all exposed ports on a container to random and available ports on the host machine. This configuration option is documented [here](https://docs.docker.com/engine/api/v1.39/#operation/ContainerCreate). --- src/builder.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index 35fccb9..631c1af 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -642,6 +642,14 @@ impl ContainerOptionsBuilder { self } + /// enable all exposed ports on the container to be mapped to random, available, ports on the host + pub fn publish_all_ports( + &mut self, + ) -> &mut Self { + self.params.insert("HostConfig.PublishAllPorts", json!(true)); + self + } + pub fn expose( &mut self, srcport: u32, @@ -1707,6 +1715,19 @@ mod tests { ); } + /// Test container option PublishAllPorts + #[test] + fn container_options_publish_all_ports() { + let options = ContainerOptionsBuilder::new("test_image") + .publish_all_ports() + .build(); + + assert_eq!( + r#"{"HostConfig":{"PublishAllPorts":true},"Image":"test_image"}"#, + options.serialize().unwrap() + ); + } + /// Test container options that are nested 3 levels deep. #[test] fn container_options_nested() { -- cgit v1.2.3