diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index 986f4a72a245..be9690966aa6 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -701,7 +701,7 @@ func DaemonHost(driver string) string { if driver == Docker { if dh := os.Getenv(constants.DockerHostEnv); dh != "" { if u, err := url.Parse(dh); err == nil { - if u.Host != "" { + if u.Hostname() != "" { return u.Hostname() } } @@ -717,14 +717,14 @@ func IsExternalDaemonHost(driver string) bool { if driver == Podman { if dh := os.Getenv(constants.PodmanContainerHostEnv); dh != "" { if u, err := url.Parse(dh); err == nil { - return u.Host != "" + return u.Hostname() != "" } } } if driver == Docker { if dh := os.Getenv(constants.DockerHostEnv); dh != "" { if u, err := url.Parse(dh); err == nil { - return u.Host != "" + return u.Hostname() != "" } } } diff --git a/pkg/drivers/kic/oci/oci_test.go b/pkg/drivers/kic/oci/oci_test.go index f31df575b699..c8befe2c987b 100644 --- a/pkg/drivers/kic/oci/oci_test.go +++ b/pkg/drivers/kic/oci/oci_test.go @@ -130,6 +130,7 @@ func TestDaemonHost(t *testing.T) { {"docker", "", "unix:///var/run/something", "127.0.0.1", false}, {"docker", "", "tcp://127.0.0.1/foo", "127.0.0.1", true}, {"docker", "", "ssh://127.0.0.1/bar", "127.0.0.1", true}, + {"docker", "", "tcp://:", "127.0.0.1", true}, } for _, test := range tests { t.Setenv("CONTAINER_HOST", test.containerHost)