Search code examples
javaazureazure-container-instancesazure-container-registryazure-authentication

how to authorize azure container registry in java to get list of repos and images under that


I have Azure container registry, My use case is through java code

I want to get all the repos of azure container registry instance. From each repo I need the list of all container images Want to push the container images and pull the container images from the repo.

Can you please help ne what java SDK, I need to use. How can i authenticate through java code to connect azure container registry. Also i have service principle account - how can I use this in java


Solution

  • It seems Azure does not provide the SDK to get a list of repos and images. But actually, the Azure Container Registry is a private docker registry. So you can use the Docker API to get the things you need. For example, you want to get a list of the repos in ACR, then you can use the API like below:

    curl -L -H "Authorization: basic $credential" https://myacr.azurecr.io/v2/_catalog
    

    The example result:

    enter image description here

    When you use a service principal as the credential of the ACR, you need to assign the service principal a role with enough permissions. You can get more details about the Docker API.