Docker如何能够获得200的返回代码而不是401?

huangapple go评论107阅读模式
英文:

How does docker manage to get a return code of 200 instead of 401

问题

在工作中,Docker无法拉取镜像:

[b209d3c5] +job pull(ubuntu, )
[debug] registry.go:372 [registry] 调用 GET https://index.docker.io/v1/repositories/ubuntu/images
[debug] http.go:160 https://index.docker.io/v1/repositories/ubuntu/images -- HEADERS: map[User-Agent:[docker/1.0.0 go/go1.2.2 git-commit/63fe64c kernel/3.15.1-1-ARCH os/linux arch/amd64]]
[debug] server.go:1182 检索标签列表
[debug] http.go:160 https://cdn-registry-1.docker.io/v1/repositories/library/ubuntu/tags -- HEADERS: map[User-Agent:[docker/1.0.0 go/go1.2.2 git-commit/63fe64c kernel/3.15.1-1-ARCH os/linux arch/amd64]]
[debug] registry.go:327 从 https://cdn-registry-1.docker.io/v1/repositories/library/ubuntu/tags 获取状态码 401
[error] server.go:1185 无法连接到任何注册表端点
无法连接到任何注册表端点
[b209d3c5] -job pull(ubuntu, ) = ERR (1)

如果我手动尝试访问第二个URL,结果也会可靠地返回401。

然而,在家里,相同的命令以某种方式成功地检索到了标签:

[4e9acee4] +job pull(ubuntu, )
[debug] registry.go:372 [registry] 调用 GET https://index.docker.io/v1/repositories/ubuntu/images
[debug] http.go:160 https://index.docker.io/v1/repositories/ubuntu/images -- HEADERS: map[User-Agent:[docker/1.0.0 go/go1.2.2 git-commit/63fe64c kernel/3.14.6-1-ARCH os/linux arch/amd64]]
[debug] server.go:1182 检索标签列表
[debug] http.go:160 https://cdn-registry-1.docker.io/v1/repositories/library/ubuntu/tags -- HEADERS: map[User-Agent:[docker/1.0.0 go/go1.2.2 git-commit/63fe64c kernel/3.14.6-1-ARCH os/linux arch/amd64]]
[debug] registry.go:327 从 https://cdn-registry-1.docker.io/v1/repositories/library/ubuntu/tags 获取状态码 200
[debug] server.go:1197 注册标签
[...]

问题是:这个Docker实例是如何获得200的结果的?

有没有一种好的方法来检查通信?(Wireshark可能不适用,因为HTTPS是完全加密的。)

可能唯一的方法是阅读源代码。但是我对Go语言了解不多。

你能想到任何更好的解决方案吗?比如自己构建Docker并添加一些调试打印信息?

英文:

At work docker is not able to pull images:

[b209d3c5] +job pull(ubuntu, )
[debug] registry.go:372 [registry] Calling GET https://index.docker.io/v1/repositories/ubuntu/images
[debug] http.go:160 https://index.docker.io/v1/repositories/ubuntu/images -- HEADERS: map[User-Agent:[docker/1.0.0 go/go1.2.2 git-commit/63fe64c kernel/3.15.1-1-ARCH os/linux arch/amd64]]
[debug] server.go:1182 Retrieving the tag list
[debug] http.go:160 https://cdn-registry-1.docker.io/v1/repositories/library/ubuntu/tags -- HEADERS: map[User-Agent:[docker/1.0.0 go/go1.2.2 git-commit/63fe64c kernel/3.15.1-1-ARCH os/linux arch/amd64]]
[debug] registry.go:327 Got status code 401 from https://cdn-registry-1.docker.io/v1/repositories/library/ubuntu/tags
[error] server.go:1185 Could not reach any registry endpoint
Could not reach any registry endpoint
[b209d3c5] -job pull(ubuntu, ) = ERR (1)

If I manually try to access that second URL it reliably results in a 401, too.

However at home the same command somehow manages to successfully retrieve the tags:

[4e9acee4] +job pull(ubuntu, )
[debug] registry.go:372 [registry] Calling GET https://index.docker.io/v1/repositories/ubuntu/images
[debug] http.go:160 https://index.docker.io/v1/repositories/ubuntu/images -- HEADERS: map[User-Agent:[docker/1.0.0 go/go1.2.2 git-commit/63fe64c kernel/3.14.6-1-ARCH os/linux arch/amd64]]
[debug] server.go:1182 Retrieving the tag list
[debug] http.go:160 https://cdn-registry-1.docker.io/v1/repositories/library/ubuntu/tags -- HEADERS: map[User-Agent:[docker/1.0.0 go/go1.2.2 git-commit/63fe64c kernel/3.14.6-1-ARCH os/linux arch/amd64]]
[debug] registry.go:327 Got status code 200 from https://cdn-registry-1.docker.io/v1/repositories/library/ubuntu/tags
[debug] server.go:1197 Registering tags
[...]

The question is: How did this docker instance manage to get a 200 result?

Is there a good way to inspect the communication? (Wireshark is probably not good as https is completely encrypted.)

Probably the only way is reading the source code. But I don't know much about the go language.

Can you think of any better solution that, building docker on my own and adding some debugging prints?

答案1

得分: 1

似乎这个 REST 调用需要一个有效的 Authorization: Token ... 头部。而且似乎公司的代理服务器破坏了这个头部。:(

从源代码构建 Docker 真的很简单。

英文:

Seems like that REST call requires a valid Authorization: Token ... header. Also seems like the company proxy breaks that header. Docker如何能够获得200的返回代码而不是401?

Building docker from source is really painless.

huangapple
  • 本文由 发表于 2014年6月21日 18:41:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/24340783.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定