From 3601b96600807214d74b9c77c614fa03bfae30a8 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Sun, 28 Jun 2020 11:06:46 -0400 Subject: Allow empty host port in --publish flag I didn't believe that this was actually legal, but it looks like it is. And, unlike our previous understanding (host port being empty means just use container port), empty host port actually carries the same meaning as `--expose` + `--publish-all` (that is, assign a random host port to the given container port). This requires a significant rework of our port handling code to handle this new case. I don't foresee this being commonly used, so I optimized having a fixed port number as fast path, which this random assignment code running after the main port handling code only if necessary. Fixes #6806 Signed-off-by: Matthew Heon --- pkg/specgen/specgen.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pkg/specgen/specgen.go') diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go index 3d5bf03e5..361f09379 100644 --- a/pkg/specgen/specgen.go +++ b/pkg/specgen/specgen.go @@ -435,7 +435,8 @@ type PortMapping struct { ContainerPort uint16 `json:"container_port"` // HostPort is the port number that will be forwarded from the host into // the container. - // If omitted, will be assumed to be identical to + // If omitted, a random port on the host (guaranteed to be over 1024) + // will be assigned. HostPort uint16 `json:"host_port,omitempty"` // Range is the number of ports that will be forwarded, starting at // HostPort and ContainerPort and counting up. -- cgit v1.2.3-54-g00ecf