5
votes

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;

  1. Testing the credentials with docker login - no problem.
  2. Pulling the image with docker pull mytestreg.azurecr.io/mytestimage - no problem.
  3. Swapping WithPrivateImageRegistry with WithPublicImageRegistryOnly and just using debian in WithImage - works as intented - no problem.
  4. Leaving the 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?

2
can you try .WithImage("mytestimage:latest")?LoekD

2 Answers

5
votes

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.

5
votes

I had the same problems for the last couple of weeks and I've finally found a solution. You should add your azure registry server name in front of the image name. So following your example change:

.WithImage("mytestimage/latest")

To:

.WithImage("mytestreg.azurecr.io/mytestimage:latest")

At least that did it for me, I hope it helps someone else.