Docker注册表名称解析 [英] Docker Registry name resolution
问题描述
我正在为Docker Registry开发一个简单的REST客户端。对于私人注册表,名称解析非常简单。如果图像名称为 myregistry.io/myimage:latest
,则查找 https://myregistry.io/v2
I'm working on a simple REST client for Docker Registry. For private registries, name resolution is pretty simple; if the image name is myregistry.io/myimage:latest
, I look for https://myregistry.io/v2
and query the API there.
但是,我注意到对于docker hub,它并不是完全有效的。如果我正在寻找 ubuntu
,可以将其扩展为 docker.io/ubuntu:latest
,但 https://docker.io/v2
返回307重定向到 https://www.docker.com/v2
,只是返回HTML。实际的注册表终结点位于 https://registry-1.docker.io/v2
。
However, I notice that for docker hub, it doesn't quite work that way. If I'm looking for ubuntu
, I can expand that to docker.io/ubuntu:latest
, but https://docker.io/v2
returns a 307 redirect to https://www.docker.com/v2
, which just returns HTML. The actual registry endpoint is at https://registry-1.docker.io/v2
.
这只是Docker客户端中的硬编码特殊情况,还是查找我不知道的注册表端点有其他逻辑?如果只是一种特殊情况,那么比往常去 registry-1.docker.io
而不是 docker.io ?
Is this just a hardcoded special case in the docker client, or is there some extra logic to looking up registry endpoints that I'm unaware of? If it is just a special case, is there more to it than always going to registry-1.docker.io
instead of docker.io
?
推荐答案
中央Docker注册表是一个众所周知的特殊情况,类似于Maven Central。您可以看到默认值,例如在 https://github.com /docker/docker-ce/blob/ea449e9b10cebb259e1a43325587cd9a0e98d0ff/components/engine/registry/config.go#L42 :
The central Docker registry is a well-known special case, similar to Maven central. You can see the defaults e.g. at 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",
}
)
这篇关于Docker注册表名称解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!