Docker.DotNet icon indicating copy to clipboard operation
Docker.DotNet copied to clipboard

Support for Azure container registry?

Open bipkris opened this issue 6 years ago • 10 comments

Does Docker.Dotnet support authentication with private docker registries such as Azure Container registry to pull down images? If so, could an example of how to pass an AAD token through the AuthConfig object be added to the documentation.

bipkris avatar Mar 09 '18 23:03 bipkris

I have the same questions. Is it possible? Would be nice with example and also how to push image to Azure Container registry

andtii avatar Mar 27 '18 12:03 andtii

To my knowledge this support is not possible with the current Docker.DotNet. We didn't have a need for it in our applications. If you would like to contribute the changes to support it I am more than willing to help/review/provide feedback to get it up and running.

jterry75 avatar Mar 27 '18 20:03 jterry75

I don't think Azure Container Registry supports AAD token. AFAIK, they rely on docker login which simply takes your AAD service principal and password for it. For that, you can use authconfig in following pattern and pass in the object when creating/pulling the image from ACR. AuthConfig authConfig = new AuthConfig() { Username = this.UserName, Password = this.Password, ServerAddress = this.ServerAddress };

await this.dockerClient.Images.CreateImageAsync( new ImagesCreateParameters() { FromImage = imageName, FromSrc = this.ServerAddress, Tag = this.Version }, authConfig, progress, cancellationToken);

HTH.

ghost avatar Apr 02 '18 21:04 ghost

Hi,

I'm trying to pull from a private registry, but looks like Docker.DotNet is anyway trying to pull from Docker Hub:

await client.Images.CreateImageAsync(
    parameters: new ImagesCreateParameters()
        {
            FromImage = "myrepo/myimage",
            FromSrc = "myCustomRegistry:5000",
            Tag = "latest",
        },
            authConfig: new AuthConfig()
                {
                    ServerAddress = "http://myCustomRegistry:5000",
                    Username = username,
                    Password = password
                },
                progress: new Progress<JSONMessage>((message) =>
                    {
                        // omitted for brevity
                    }));

The output I get is:

response={"message":"Get https://registry-1.docker.io/v2/myrepo/myimage/manifests/latest: unauthorized: incorrect username or password"}

It appears that Docker Client is anyway trying to get the image from Docker hub and ignoring ImagesCreateParameters.FromSrc and/or AuthConfig.ServerAddress

Am I missing anything here?

Thanks

vinisoto avatar May 12 '18 06:05 vinisoto

  1. ServerAddress field in AuthConfig would be the address of your docker images host ending in ".io"
  2. FromImage field in ImagesCreateParameters would be of format ServiceAddress/ImageName:version

ghost avatar May 13 '18 10:05 ghost

Thank you @prashantbhutani90. That did the trick.

vinisoto avatar May 14 '18 18:05 vinisoto

@vinisoto hey, I have recently started developing with docker.dotnet and azure cr. I was hoping you could give me some tips if you have completed some examples. Mine are pretty basic for now. if you can contact me on [email protected] it would be great, or any other means :)

thanks

spoon252 avatar Aug 17 '18 10:08 spoon252

Is this supported yet?

Bigshooter avatar Apr 23 '19 17:04 Bigshooter

I don't think Azure Container Registry supports AAD token. AFAIK, they rely on docker login which simply takes your AAD service principal and password for it. For that, you can use authconfig in following pattern and pass in the object when creating/pulling the image from ACR. AuthConfig authConfig = new AuthConfig() { Username = this.UserName, Password = this.Password, ServerAddress = this.ServerAddress };

await this.dockerClient.Images.CreateImageAsync( new ImagesCreateParameters() { FromImage = imageName, FromSrc = this.ServerAddress, Tag = this.Version }, authConfig, progress, cancellationToken);

HTH.

@prashantbhutani90 I tried your suggestion but am still running into issues. I get the error regarding the URL like @vinisoto where it's pulling from docker.io instead of azure. (e.g. https://registry-1.docker.io/v2/myrepo/myimage/manifests/latest)

I tried this also, which you suggested which is also giving me an error:

            {
                await dockerClient.Images.CreateImageAsync(
                    new ImagesCreateParameters
                    {
                        FromImage = "https://myregistry.azurecr.io/myimage:version"
                    }, 
                    new AuthConfig
                    {
                        Username = {username}, 
                        Password = {password},
                        ServerAddress = "https://myregistry.azurecr.io"
                    }, 
                    null);

But I get this:

Docker API responded with status code=BadRequest, response={"message":"invalid reference format"}

What am I missing?

kakins avatar Jun 17 '21 14:06 kakins

Is there any way to not have a username/password combo for this and use the token from DefaultAzureCredential?

philip-reed avatar Nov 20 '23 15:11 philip-reed