如何解决docker-registry - 来自 python 的 PUT 请求响应 400,但 Curl 工作正常
我正在尝试从我的私有注册表中 GET
一个清单 v2,然后PUT
将它放回到不同的标签下。我正在用 Python 编写的实用程序(requests
lib)
如果我将所需图像的清单保存到 JSON 文件中,然后执行 curl
命令:
curl -XPUT 'http://localhost:5000/v2/<repository>/manifests/latest' -H 'content-type: application/vnd.docker.distribution.manifest.v2+json' -d @manifest.json
- 它可以工作并以 2xx 响应。但是如果我尝试用 Python 来做:
manifest = requests.get(url='http://localhost:5000/v2/%s/manifests/%s' % (img,tag),headers={'Accept': 'application/vnd.docker.distribution.manifest.v2+json'})
put_latest = requests.put(url='http://localhost:5000/v2/%s/manifests/latest' % image,headers={'Accept': 'application/vnd.docker.distribution.manifest.v2+json'},data=manifest.text)
-它只是响应 400 Bad Request
和 {'errors': [{'code': 'MANIFEST_INVALID','message': 'manifest invalid','detail': {}}]}
,并且在 docker-registry
日志中显示 err.detail="missing signature key"
。
做错了什么?
解决方法
我发送了错误的标题密钥。我想我应该使用 Content-Type
而不是 Accept
,后者用于 GET
。
manifest = requests.get(url='http://localhost:5000/v2/%s/manifests/%s' % (img,tag),headers={'Accept': 'application/vnd.docker.distribution.manifest.v2+json'})
put_latest = requests.put(url='http://localhost:5000/v2/%s/manifests/latest' % image,headers={'Content-Type': 'application/vnd.docker.distribution.manifest.v2+json'},data=manifest.text)