feat: wip implement port forwarding
This commit is contained in:
@@ -2,6 +2,7 @@ package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"strconv"
|
||||
@@ -19,3 +20,16 @@ func ContainerSSHHostPort(ctx context.Context, container types.ContainerJSON) in
|
||||
}
|
||||
return port
|
||||
}
|
||||
|
||||
// ContainerHostPort finds the host port that is exposing the given container port
|
||||
func ContainerHostPort(ctx context.Context, container types.ContainerJSON, port int) int {
|
||||
ports := container.NetworkSettings.Ports[nat.Port(fmt.Sprintf("%d/tcp", port))]
|
||||
if len(ports) == 0 {
|
||||
return -1
|
||||
}
|
||||
port, err := strconv.Atoi(ports[0].HostPort)
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
return port
|
||||
}
|
||||
|
Reference in New Issue
Block a user