Docker.DotNet
Docker.DotNet copied to clipboard
Support for Azure container registry?
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.
I have the same questions. Is it possible? Would be nice with example and also how to push image to Azure Container registry
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.
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.
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
- ServerAddress field in AuthConfig would be the address of your docker images host ending in ".io"
- FromImage field in ImagesCreateParameters would be of format ServiceAddress/ImageName:version
Thank you @prashantbhutani90. That did the trick.
@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
Is this supported yet?
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?
Is there any way to not have a username/password combo for this and use the token from DefaultAzureCredential
?