summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-06-29 13:52:47 -0400
committerGitHub <noreply@github.com>2020-06-29 13:52:47 -0400
commite0b93af70f1f1a183c99a350c6e588898b45c717 (patch)
tree77271b38b5e61bff58ab3ba6f8e58b0ab48645cb /cmd
parentc682ca3d35a3e4f9265e10dc9898cbe3ac3d35a2 (diff)
parent3601b96600807214d74b9c77c614fa03bfae30a8 (diff)
downloadpodman-e0b93af70f1f1a183c99a350c6e588898b45c717.tar.gz
podman-e0b93af70f1f1a183c99a350c6e588898b45c717.tar.bz2
podman-e0b93af70f1f1a183c99a350c6e588898b45c717.zip
Merge pull request #6808 from mheon/allow_empty_hostport
Allow empty host port in --publish flag
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common/util.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/cmd/podman/common/util.go b/cmd/podman/common/util.go
index ce323a4ba..6c8c22147 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