Azure容器注册表-列出图像/标签-以编程方式 [英] Azure Container Registry - List Images / Tags - Programmatically

查看:51
本文介绍了Azure容器注册表-列出图像/标签-以编程方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在砸墙,试图弄清楚如何以编程方式在Azure容器注册表中获取图像列表.

一切似乎都归结于Docker.DotNet自己的图像列表的 local 实例化实例,并通过该本地存储库推/拉到ACR-但没有任何东西向我展示如何获取ACR本身的图像(及其标签)列表.在探究其余的API以获得天蓝色时,似乎只有一小部分管理"选项可用(获取ACR列表,获取ACR的属性,但没有什么比这更深入地了解我了).

我可以通过Azure CLI获取图像名称列表,然后获得其图像名称标签-但是我希望在C#应用程序中获得可枚举的图像列表(web-api,事实上).

基本上-我想做的是在docker中远程运行图像列表-并将那些与ACR中的内容进行比较,以给出一个嘿,有一个更新的版本该图像的可用".

有人这样做吗?有效果吗?

(对于Docker)这样简单吗?

  var _credentials = new BasicAuthCredentials("MY_REG_USERNAME","MY_REG_PASSWORD");var _config = new DockerClientConfiguration(new Uri("MY_REGISTRY_NAME.azurecr.io"),_credentials);DockerClient _client = _config.CreateClient();var myList =等待_client.Images.ListImagesAsync(新的Docker.DotNet.Models.ImagesListParameters(){全部= true}); 

还是不可能?

我已经用DeviceClient弄乱了IoT中心并获取了设备孪生列表等信息-ACR上没有这样的东西吗?

解决方案

一段时间以来,我面临着同样的难题,答案是:

对于图像操作(包括您询问的标签列表),Microsoft支持docker Registry API v2.

https://docs.docker.com/registry/spec/api

是什么意思?一个例子:

Azure REST API仅适用于Azure资源操作.在那里,您可以使用Bearer Token身份验证,例如发出GET请求,如下所示:

https://management.azure.com/subscriptions/SubscriptionGUID/resourceGroups/ContainerRegistry/providers/Microsoft.ContainerRegistry/registries/YourRegistryName?api-version=2017-10-01

但是您已经知道,这将使您无法访问有关ACR内容的操作.

相反,您需要调用另一个端点,即注册表端点,并且非常重要的是,您需要使用具有用户名和密码的基本身份验证:

https://yourregistryname-on.azurecr.io/v2/imagename/tags/list

它是什么用户名和密码?好吧,可能有两种类型:

  1. 您可以在Azure门户中的ACR上启用的管理员用户
  2. 您可以在ACR中的访问控制"下为用户配置不同类型的访问(更安全).作为用户名,您可以使用底层的GUID,当在Azure门户中选择该GUID时,该查询在URL的查询字符串中可见.密码/密钥也可以在那里配置.

I'm bashing my head against the wall to try and figure out how to programmatically get a list of images in an Azure Container Registry.

Everything seems to fall down to looking in Docker.DotNet's own local instantiation of an image list, and push/pulling to an ACR via that local repository - but nothing is showing me how to get a list of images (and their tags) from the ACR itself. In digging through their rest API for azure, it looks like only a slim set of "management" options are available (getting a list of ACRs, getting the properties of an ACR, but nothing shows me it dives deeper than that).

I can get a list of image names, and then their image name tags via the Azure CLI -- but I'm looking to get an enumerable list of images in a C# app (inside a web-api, matter of fact).

Essentially - what I want to do is have a list of running images remotely, in docker -- and compare those to what's up in the ACR, to give a "hey, there's a newer version of this image available".

Has anyone done this? To any effect?

Is it simple like this (for Docker):

    var _credentials = new BasicAuthCredentials("MY_REG_USERNAME", "MY_REG_PASSWORD");
    var _config = new DockerClientConfiguration(new Uri("MY_REGISTRY_NAME.azurecr.io"), _credentials);
    DockerClient _client = _config.CreateClient();

    var myList = await _client.Images.ListImagesAsync(
             new Docker.DotNet.Models.ImagesListParameters() { All = true }
     );

or impossible?

I've messed around with IoT hubs and getting device twin lists and the like, with the DeviceClient -- is there nothing like this for the ACR?

解决方案

I was facing the same puzzle for a while and the answer is:

For image operations (including the tag list you were asking about) Microsoft supports the docker registry API v2.

https://docs.docker.com/registry/spec/api

What does it mean? An Example:

Azure REST API is for Azure resource operations only. There you can use Bearer Token authentication and for example make a GET request like this:

https://management.azure.com/subscriptions/SubscriptionGUID/resourceGroups/ContainerRegistry/providers/Microsoft.ContainerRegistry/registries/YourRegistryName?api-version=2017-10-01

But as you already know this will not give you access to operations on the content of the ACR.

Instead you need to call a different end-point, namely the Registry end-point, and very importantly, you need to use basic authentication with username and password:

https://yourregistryname-on.azurecr.io/v2/imagename/tags/list

What username and password is it? Well, there are 2 types possible:

  1. The admin user you can enable on the ACR in the Azure portal
  2. You can configure users in the ACR under Access Control with different types of access (more secure). As the username you can use the underlying GUID, visible in the query string in the URL when selecting it in Azure portal. Password/key can be configured there as well.

这篇关于Azure容器注册表-列出图像/标签-以编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆