Merge pull request #9237 from afbjorklund/podman2-port

Fix ForwardedPort for podman version 2.0.1 and up
pull/9267/head
Medya Ghazizadeh 2020-09-15 14:51:44 -07:00 committed by GitHub
commit 48a32a02a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -252,7 +252,9 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
validateFlags(cmd, driverName)
validateUser(driverName)
validateDockerStorageDriver(driverName)
if driverName == oci.Docker {
validateDockerStorageDriver(driverName)
}
// Download & update the driver, even in --download-only mode
if !viper.GetBool(dryRun) {

View File

@ -24,6 +24,7 @@ import (
"strconv"
"strings"
"github.com/blang/semver"
"github.com/golang/glog"
"github.com/pkg/errors"
)
@ -124,8 +125,22 @@ func containerGatewayIP(ociBin, containerName string) (net.IP, error) {
func ForwardedPort(ociBin string, ociID string, contPort int) (int, error) {
var rr *RunResult
var err error
var v semver.Version
if ociBin == Podman {
rr, err = runCmd(exec.Command(Podman, "version", "--format", "{{.Version}}"))
if err != nil {
return 0, errors.Wrapf(err, "podman version")
}
output := strings.TrimSpace(rr.Stdout.String())
v, err = semver.Make(output)
if err != nil {
return 0, errors.Wrapf(err, "podman version")
}
}
// podman 2.0.1 introduced docker syntax for .NetworkSettings.Ports (podman#5380)
if ociBin == Podman && v.LT(semver.Version{Major: 2, Minor: 0, Patch: 1}) {
rr, err = runCmd(exec.Command(ociBin, "container", "inspect", "-f", fmt.Sprintf("{{range .NetworkSettings.Ports}}{{if eq .ContainerPort %s}}{{.HostPort}}{{end}}{{end}}", fmt.Sprint(contPort)), ociID))
if err != nil {
return 0, errors.Wrapf(err, "get port %d for %q", contPort, ociID)