Merge pull request #9237 from afbjorklund/podman2-port
Fix ForwardedPort for podman version 2.0.1 and uppull/9267/head
commit
48a32a02a8
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue