简体   繁体   English

如何验证docker hub api请求?

[英]How to authenticate docker hub api request?

I have been trying for the past several hours to make an authenticated request to the docker hub api. 在过去的几个小时里,我一直在尝试向docker hub api发出经过身份验证的请求。 First of all, let me say that their documentation is very unclear. 首先,我要说他们的文件很不清楚。 There are several different subdomains that you have to cycle through. 您必须循环使用几个不同的子域。 The ones I have seen are index.dockerhub.io, registry-1.docker.io/v1/ auth.docker.com/token. 我见过的是index.dockerhub.io,registry-1.docker.io / v1 / auth.docker.com/token。 There were others. 还有其他人。 But you get the point. 但你明白了。 Its like their api is managed by 30 different people or something and they forgot to have a meeting about how to unify their api. 它就像他们的api由30个不同的人或其他人管理,他们忘了开会讨论如何统一他们的api。 It feels like I have read just about everything I could find on the internet about how to do what I am trying to do, and it still is very unclear to me what I am supposed to do. 感觉就像我在互联网上找到了关于如何做我想做的事情的一切,而且我仍然不清楚我应该做什么。

Their documentation states that I am supposed to get an auth token before making certain request. 他们的文档说明我应该在做出某些请求之前获得一个身份验证令牌。 Ok. 好。 Fine. 精细。 How do I do that? 我怎么做? I got lucky and stumbled across the endpoint, https://auth.docker.io/v2/token/ no thanks to their api. 我很幸运,偶然发现了端点, https://auth.docker.io/v2/token/不,谢谢他们的api。 I found it by just guessing. 我只是猜测就找到了。 I don't know that version 2 is capable of even doing what I am trying to do. 我不知道版本2能够做我想做的事情。

What steps do I need to take to make authenticated request to the dockerhub api. 我需要采取哪些步骤来对dockerhub api进行身份验证请求。 What I am trying to do more specifically, is I am trying to query information about the given images that are on the hub, like the size of the images, and the basic port information that is available. 我想要更具体地做的是,我正在尝试查询有关集线器上给定图像的信息,例如图像的大小以及可用的基本端口信息。 I know its possible, because I have used services that do it. 我知道它可能,因为我已经使用过它的服务。 So, how do you properly authenticate request to get this information? 那么,您如何正确验证获取此信息的请求?

So after a few more hours of working on this problem, I came across someone who had similar issues and wrote a blog post about exactly how to solve it. 因此,经过几个小时的处理这个问题,我遇到了一个有类似问题的人,写了一篇关于如何解决它的博客文章。 The short answer is the endpoint that was missing from the docker api documentation is https://cdn-registry-1.docker.io/v1/ . 简短的回答是docker api文档中缺少的端点是https://cdn-registry-1.docker.io/v1/ Why didn't they document their api better? 他们为什么不更好地记录他们的api? I don't know. 我不知道。 If anyone wants to read the full article about how this is done, you can find it at http://www.appcontainers.com/requesting-image-information-using-the-public-docker-api/ 如果有人想阅读有关如何完成的完整文章,您可以在http://www.appcontainers.com/requesting-image-information-using-the-public-docker-api/找到它

This was the most helpful article I have found on the subject. 这是我在这个主题上找到的最有帮助的文章。 Hopefully this will help some other poor soul who is trapped in the confusion known as the docker api. 希望这将有助于一些被困在被称为docker api的混乱中的其他可怜的灵魂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM