使用 HTTP 公开 API 时 Docker 拉取失败

问题描述

我想做什么

当通过 http 使用公开的守护进程时,我需要能够拉取存储在 Docker 集线器中的私有镜像

http://127.0.0.1:2375/v1.35/images/create?fromImage=akkovachev/test-repository

“akkovachev/test-repository”是 docker hub 中的一个私有仓库,当我运行上面的 POST 请求时,我得到

{
    "message": "pull access denied for akkovachev/test-repository,repository does not exist or may require 'docker login': denied: requested access to the resource is denied"
}

所以可能我遗漏了一些东西,但我不明白是什么。我试图做的是使用 base64 编码的 uname:password 在文件中更改身份验证

./docker/config.json

我也尝试了此处描述的格式的 base64 编码标头 https://docs.docker.com/engine/api/v1.35/#section/Authentication 但同样的问题。我在这里发帖是我最后的手段,因为我无法很好地解释为什么会发生这种情况。许多人说他们面临同样的问题,但主要是在 CLI 中。我在 Windows 上使用 Docker 版本 v20.10.5。

请务必注意,仅当我尝试通过暴露的 HTTP 恶魔执行此操作时才会出现此问题。当我在 CLI 中执行时它工作正常

docker pull akkovachev/test-repository

Evertyghing 按预期工作,图像被正确拉取

我需要能够通过 API,因为我有自己的 Rest api 构建,我需要能够通过暴露的 docker 守护进程。

我在 Postman 中使用的标题

enter image description here

解决方法

我很想弄清楚。问题出在我们作为 X-Registry-Auth 标头传递的 base64 编码字符串中。我在 json 中缺少“serveraddress”属性

{
  "username": "string","password": "string","email": "string","serveraddress": "string"
}

我添加并指向 https://index.docker.io/v1/ 然后它工作得很好