diff --git a/cli/config/credentials/file_store.go b/cli/config/credentials/file_store.go index 99631bbf4c..2b37769c36 100644 --- a/cli/config/credentials/file_store.go +++ b/cli/config/credentials/file_store.go @@ -74,7 +74,10 @@ func ConvertToHostname(maybeURL string) string { if strings.Contains(stripped, "://") { u, err := url.Parse(stripped) if err == nil && u.Hostname() != "" { - return u.Hostname() + if u.Port() == "" { + return u.Hostname() + } + return u.Hostname() + ":" + u.Port() } } hostName, _, _ := strings.Cut(stripped, "/") diff --git a/cli/config/credentials/file_store_test.go b/cli/config/credentials/file_store_test.go index 74d63afcd6..436a3c8121 100644 --- a/cli/config/credentials/file_store_test.go +++ b/cli/config/credentials/file_store_test.go @@ -167,6 +167,23 @@ func TestConvertToHostname(t *testing.T) { input: "ftp://example.com", expected: "example.com", }, + // should support non-standard port in registry url + { + input: "example.com:6555", + expected: "example.com:6555", + }, + { + input: "http://example.com:6555", + expected: "example.com:6555", + }, + { + input: "https://example.com:6555", + expected: "example.com:6555", + }, + { + input: "https://example.com:6555/v2/", + expected: "example.com:6555", + }, } for _, tc := range tests { tc := tc