我正在为Docker Registry开发一个简单的REST客户端。对于私人注册管理机构,名称解析非常简单;如果图片名称为myregistry.io/myimage:latest
,我会查找https://myregistry.io/v2
并在那里查询API。
但是,我注意到对于docker hub来说,它并不是那么有效。如果我正在寻找ubuntu
,我可以将其扩展为docker.io/ubuntu:latest
,但https://docker.io/v2
会返回307重定向到https://www.docker.com/v2
,这只会返回HTML。实际的注册表端点位于https://registry-1.docker.io/v2
。
这只是docker客户端中的一个硬编码特殊情况,还是有一些额外的逻辑来查找我不知道的注册表端点?如果只是一个特殊情况,那么除了registry-1.docker.io
而不是docker.io
之外还有更多吗?
答案 0 :(得分:1)
中央Docker注册表是一个众所周知的特例,类似于Maven central。你可以看到默认值,例如在https://github.com/docker/docker-ce/blob/ea449e9b10cebb259e1a43325587cd9a0e98d0ff/components/engine/registry/config.go#L42:
var (
// DefaultNamespace is the default namespace
DefaultNamespace = "docker.io"
// DefaultRegistryVersionHeader is the name of the default HTTP header
// that carries Registry version info
DefaultRegistryVersionHeader = "Docker-Distribution-Api-Version"
// IndexHostname is the index hostname
IndexHostname = "index.docker.io"
// IndexServer is used for user auth and image search
IndexServer = "https://" + IndexHostname + "/v1/"
// IndexName is the name of the index
IndexName = "docker.io"
// DefaultV2Registry is the URI of the default v2 registry
DefaultV2Registry = &url.URL{
Scheme: "https",
Host: "registry-1.docker.io",
}
)