in sources/host-ctr/cmd/host-ctr/main.go [996:1039]
func registryHosts(registryConfig *RegistryConfig, authorizer docker.Authorizer) docker.RegistryHosts {
return func(host string) ([]docker.RegistryHost, error) {
var (
registries []docker.RegistryHost
endpoints []string
)
if _, ok := registryConfig.Mirrors[host]; ok {
endpoints = registryConfig.Mirrors[host].Endpoints
} else {
endpoints = registryConfig.Mirrors["*"].Endpoints
}
defaultHost, err := docker.DefaultHost(host)
if err != nil {
return nil, errors.Wrap(err, "get default host")
}
endpoints = append(endpoints, defaultHost)
for _, endpoint := range endpoints {
// Prefix the endpoint with an appropriate URL scheme if the endpoint does not have one.
if !strings.Contains(endpoint, "://") {
if endpoint == "localhost" || endpoint == "127.0.0.1" || endpoint == "::1" {
endpoint = "http://" + endpoint
} else {
endpoint = "https://" + endpoint
}
}
url, err := url.Parse(endpoint)
if err != nil {
return nil, errors.Wrapf(err, "parse registry endpoint %q from mirrors", endpoint)
}
if url.Path == "" {
url.Path = "/v2"
}
registries = append(registries, docker.RegistryHost{
Authorizer: authorizer,
Host: url.Host,
Scheme: url.Scheme,
Path: url.Path,
Capabilities: docker.HostCapabilityResolve | docker.HostCapabilityPull,
})
}
return registries, nil
}
}