Files
tesseract/internal/docker/docker.go

22 lines
524 B
Go
Raw Normal View History

2024-11-17 18:10:35 +00:00
package docker
import (
"context"
"github.com/docker/docker/api/types"
"github.com/docker/go-connections/nat"
"strconv"
)
// ContainerSSHHostPort returns the port on the host that is exposing the internal ssh port of the given container info
func ContainerSSHHostPort(ctx context.Context, container types.ContainerJSON) int {
ports := container.NetworkSettings.Ports[nat.Port("22/tcp")]
if len(ports) == 0 {
return -1
}
port, err := strconv.Atoi(ports[0].HostPort)
if err != nil {
return -1
}
return port
}