diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-07-06 15:55:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-06 15:55:15 -0400 |
commit | e3e2b1e65930bfc40c5b60802c4d6ea175169732 (patch) | |
tree | de9fbf65281b2d9e69eaa90be2bdee96d3047d5c /cmd/podman/common/util.go | |
parent | b8ad7f241aba622b23b2cfab6fb5284cd26125e3 (diff) | |
parent | 2fb9bb20df49f665dbc7420a80dc2da57530278f (diff) | |
download | podman-e3e2b1e65930bfc40c5b60802c4d6ea175169732.tar.gz podman-e3e2b1e65930bfc40c5b60802c4d6ea175169732.tar.bz2 podman-e3e2b1e65930bfc40c5b60802c4d6ea175169732.zip |
Merge pull request #6871 from mheon/202_backports
Backports for v2.0.2
Diffstat (limited to 'cmd/podman/common/util.go')
-rw-r--r-- | cmd/podman/common/util.go | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/cmd/podman/common/util.go b/cmd/podman/common/util.go index a3ce6198c..e21e349d9 100644 --- a/cmd/podman/common/util.go +++ b/cmd/podman/common/util.go @@ -184,22 +184,24 @@ func parseSplitPort(hostIP, hostPort *string, ctrPort string, protocol *string) } if hostPort != nil { if *hostPort == "" { - return newPort, errors.Errorf("must provide a non-empty container host port to publish") - } - hostStart, hostLen, err := parseAndValidateRange(*hostPort) - if err != nil { - return newPort, errors.Wrapf(err, "error parsing host port") - } - if hostLen != ctrLen { - return newPort, errors.Errorf("host and container port ranges have different lengths: %d vs %d", hostLen, ctrLen) + // Set 0 as a placeholder. The server side of Specgen + // will find a random, open, unused port to use. + newPort.HostPort = 0 + } else { + hostStart, hostLen, err := parseAndValidateRange(*hostPort) + if err != nil { + return newPort, errors.Wrapf(err, "error parsing host port") + } + if hostLen != ctrLen { + return newPort, errors.Errorf("host and container port ranges have different lengths: %d vs %d", hostLen, ctrLen) + } + newPort.HostPort = hostStart } - newPort.HostPort = hostStart + } else { + newPort.HostPort = newPort.ContainerPort } hport := newPort.HostPort - if hport == 0 { - hport = newPort.ContainerPort - } logrus.Debugf("Adding port mapping from %d to %d length %d protocol %q", hport, newPort.ContainerPort, newPort.Range, newPort.Protocol) return newPort, nil |