I have created a Azure Container Registry, and uploaded a custom ACI to the registry - no problem - everything works as intended. I have tried creating an container instance from the image using the Azure Portal, and no problems there either - however - when I want to automate things using C# with the Microsoft Azure Management Container Instance Fluent API, I run into problems, and even though I feel like I have been all over the Internet and the settings, looking for hidden obstructions, I haven't been able to find much help.
My code is as follows:
var azureCredentials = new AzureCredentials(new
ServicePrincipalLoginInformation
{
ClientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}, "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
AzureEnvironment.AzureGlobalCloud);
var azure = Azure
.Configure()
.Authenticate(azureCredentials)
.WithSubscription("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
IContainerGroup containerGroup = azure.ContainerGroups.Define("mytestgroup")
.WithRegion(Region.EuropeWest)
.WithExistingResourceGroup("mytest-rg")
.WithLinux()
.WithPrivateImageRegistry("mytestreg.azurecr.io", "mytestreg", "xxxxxxxxxxxxxx")
.WithoutVolume()
.DefineContainerInstance("mytestgroup")
.WithImage("mytestimage/latest")
.WithExternalTcpPort(5555)
.WithCpuCoreCount(.5)
.WithMemorySizeInGB(.5)
.Attach()
.Create();
The above code keeps giving me the exception:
Microsoft.Rest.Azure.CloudException: 'The image 'mytestimage/latest' in container group 'mytestgroup' is not accessible. Please check the image and registry credential.'
I have tried a couple of things;
docker login
- no problem.docker pull mytestreg.azurecr.io/mytestimage
- no problem.WithPrivateImageRegistry
with WithPublicImageRegistryOnly
and just using debian
in WithImage
- works as intented - no problem.latest
tag out of the image name - still doesn't work.I have no idea why the credentials for the private Registry won't work - I have been copy/pasting directly from the Azure Portal to avoid typos, tried typing in manually etc.
Using Fiddler to inspect the traffic doesn't reveal anything interesting, other than the above exception message is returned directly from the Azure Management API.
What is the obvious thing that I am missing?
Create a container instance. On the Azure portal homepage, select Create a resource. Select Containers > Container Instances. On the Basics page, choose a subscription and enter the following values for Resource group, Container name, Image source, and Container image.
Deploy container with Azure CLI First get the registry's login server name by using the az acr show command. The login server name is all lowercase and similar to myregistry.azurecr.io . Execute the following az container create command to deploy a container instance.
Create a container registry using the az acr create command. The registry name must be unique within Azure, and contain 5-50 alphanumeric characters.
Authenticate using the service principal To launch a container in Azure Container Instances using a service principal, specify its ID for --registry-username , and its password for --registry-password . We recommend running the commands in the most recent version of the Azure Cloud Shell.
The answer above (ie using full azure registry server name):
.WithImage("mytestreg.azurecr.io/mytestimage:latest")
seems to be part of the solution, but even with that change I was still seeing this error. Looking through other examples on the web (https://github.com/Azure-Samples/aci-dotnet-create-container-groups-using-private-registry/blob/master/Program.cs) containing what I needed, I changed my azure authentication from:
azure = Azure.Authenticate(authFilePath).WithDefaultSubscription();
to:
AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromFile(authFilePath);
azure = Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();
and with THAT change, things are now working correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With