首页 > 解决方案 > Kubernetes 在执行 docker pull 时忽略 config.json

问题描述

我正在尝试从私有注册表中提取图像,并且我将身份验证存储在 kubernetes 集群节点的 /root/.docker/config.json 中。我还验证了在拉取 docker 映像时身份验证是否按预期工作。

curl -v \
     -X GET \
     -H "Authorization: Bearer $(cat /tmp/auth_bearer.txt)" repo-url/manifests/latest \
     -H "Accept: application/vnd.docker.distribution.manifest.v2+json"

回复:

< HTTP/1.1 200 OK < Date: Wed, 11 Mar 2020 23:27:09 GMT <
Content-Type: application/vnd.docker.distribution.manifest.v2+json <
Content-Length: 3455 < Connection: keep-alive < Vary: Origin <
opc-request-id: 772f679098749bb474d59161 < Docker-Content-Digest:
sha256:17dcbbf7c670d8894ddfefc2907c9f045bfc45e60954525635632abbf02910
< {    "schemaVersion": 2,    "mediaType":
"application/vnd.docker.distribution.manifest.v2+json",    "config": {
      "mediaType": "application/vnd.docker.container.image.v1+json",
      "size": 9504,
      "digest": "sha256:d59db4a22d6ba8f1d3b5d7c8f8f410688dee569a947bf242e6c3e3b708f634829"
},    "layers": [
      { [...]

从上面的回复中,很明显我在私人仓库位置有图像,并且身份验证是正确的。但是,当我尝试这样做时docker pull <repo-url>/image-name:image-tag,会出现此错误:

Trying to pull repository <repo-url>/image-name:image-tag ... 
pull access denied for <repo-url>/image-name:image-tag, repository does not exist or may require 'docker login'

有人可以告诉我我在这里缺少什么吗?为什么节点忽略存储在 /root/.docker/config.json 中的 docker 凭据?

标签: dockerkubernetes

解决方案


使用基于文件的配置

根据文档,有以下选项:https ://kubernetes.io/docs/concepts/containers/images/#configuring-nodes-to-authenticate-to-a-private-registry

您可以在此处列出的文件中设置 docker 机密:

  • {--root-dir:-/var/lib/kubelet}/config.json
  • {cwd of kubelet}/config.json
  • ${HOME}/.docker/config.json
  • /.docker/config.json
  • {--root-dir:-/var/lib/kubelet}/.dockercfg
  • {cwd of kubelet}/.dockercfg
  • ${HOME}/.dockercfg
  • /.dockercfg

注意:您可能必须在 kubelet 的环境文件中显式设置 HOME=/root。


推荐阅读