diff options
author | Tyler Jones <tyhampjone@gmail.com> | 2019-12-26 20:16:26 -0700 |
---|---|---|
committer | Doug Tangren <d.tangren@gmail.com> | 2019-12-26 22:16:26 -0500 |
commit | 1718105d19c53e817de9776011daacb17f6ac275 (patch) | |
tree | 5a23ddc6341e4039b6bbb0e1356abe89d27cb2b5 | |
parent | 3580c29b349585ae7de500ccb510659e9caf1500 (diff) |
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).
-rw-r--r-- | src/builder.rs | 21 |
1 files changed, 21 insertions, 0 deletions
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() { |