diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index 986f4a72a245..27730048a819 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -702,7 +702,9 @@ func DaemonHost(driver string) string { if dh := os.Getenv(constants.DockerHostEnv); dh != "" { if u, err := url.Parse(dh); err == nil { if u.Host != "" { - return u.Hostname() + if hostname := u.Hostname(); hostname != "" { + 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)