Reputation: 83
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?
Upvotes: 8
Views: 11903
Reputation: 311
While not ideal to use from within .NET, another CLI-centric way to get all the images is using az acr manifest
(the successor to az acr repository show-manifests
). This lists all the images, whether tagged or not, present in a given repository. For example:
MY_REGISTRY=<name of your registry>
MY_REPOSITORY=<name of your repository>
az acr manifest list-metadata \
--registry $MY_REGISTRY \
--name $MY_REPOSITORY \
--query '[:].[digest, imageSize, tags[:]]' \
-o table
Shows every image digest, size, and list of tags associated with that image, whether tagged or not.
Upvotes: 1
Reputation: 51
You can use https://myregistry.azurecr.io/v2/_catalog URL with basic authentication. To get username and password for basic auth, use below command from Powershell.
az acr credential show --name myregistry
Upvotes: 4
Reputation: 96
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:
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:
Upvotes: 8