Docker API推送到私有注册表错误

时间:2020-10-21 22:55:45

标签: docker api

我无法使用Docker API将图像推送到私有注册表。我读了所有到处都能找到的东西,没有运气就尝试了一切。

我尝试过:

curl -X POST -H "X-Registry-Auth:XXXXXXXXXXXXXXX" http://dockerapiurl:2375/images/registryurl/python/push?tag=6

OR

curl -X POST -H'X-Registry-Auth:{“ username”:“ xxxxxx”,“ password”:“ xxxxx”,“ serveraddress”:“ xxxx.url.net”,“ auth”:“ “}” http:// dockerapiurl:2375 / images / registryurl / python / push?tag = 6

我总是遇到相同的错误:

{“ errorDetail”:{“ message”:“错误:\ ndenied:请求的对资源的访问被拒绝\ n未授权:需要验证\ n”},“ error”:“错误:\ ndenied:请求的对资源的访问资源被拒绝\未授权:需要验证\ n“}

如果我在CLI模式下使用docker push一切正常,那么我在做什么错了?

谢谢!

1 个答案:

答案 0 :(得分:0)

它需要使用base 64进行编码,请尝试

XRA=`echo "{ \"username\": \"xxxxxx\", \"password\": \"xxxxxx\", \"email\": \"youmail@example.org\", \"serveraddress\": \"xxxxxx\" }" | base64 --wrap=0`
curl  -X POST  -d "" -H "X-Registry-Auth: $XRA" http://dockerapiurl:2375/images/registryurl/python/push?tag=6

最终结果应如下图

curl -X POST -d "" -H "X-Registry-Auth: eyAidXNlcm5hbWUiOiAieHh4eHh4IiwgInBhc3N3b3JkIjogInh4eHh4eCIsICJlbWFpbCI6ICJ5b3VtYWlsQGV4YW1wbGUub3JnIiB9Cg==" http://dockerapiurl:2375/images/registryurl/python/push?tag=6