I am attempting to programmatically create an ACI instance in .NET Core, with a simple container as below. I have to point to a private ACR to use with ACI, and the private ACR should be accessed with managed identity, in my case using the Visual Studio's logged in Azure account.
Azure.Core.TokenCredential msiTokenCred = DefaultAzureCredentialProvider.GetCredential(new DefaultAzureCredentialOptions
{
ExcludeVisualStudioCodeCredential = false,
ExcludeVisualStudioCredential = false,
TenantId = "XXXXXXXX-41bc-86f2-XXXX-72f988bfdb47"
});
// authenticate your client
ArmClient client = new ArmClient(msiTokenCred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX";
string resourceGroupName = "rg-acidemo";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this ContainerGroupResource
ContainerGroupCollection collection = resourceGroupResource.GetContainerGroups();
// invoke the operation
string containerGroupName = "demo1";
ContainerGroupData data = new ContainerGroupData(new AzureLocation("eastus"),
[
new ContainerInstanceContainer("test-container-001","myprivateacr.azurecr.io/alpine",new ContainerResourceRequirements( new ContainerResourceRequestsContent(1,1)))
{
Command =
{
"/bin/sh","-c","sleep 10"
}
}
], ContainerInstanceOperatingSystemType.Linux)
{
RestartPolicy = ContainerGroupRestartPolicy.Never,
Sku = ContainerGroupSku.Standard,
Priority = ContainerGroupPriority.Spot
};
ArmOperation<ContainerGroupResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, containerGroupName, data);
ContainerGroupResource result = lro.Value;
ContainerGroupData resourceData = result.Data;
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
This is not working and resulting in an error -
'The image 'myprivateacr.azurecr.io/alpine' in container group 'demo1' is not accessible. Please check the image and registry credential.
Status: 400 (Bad Request)
ErrorCode: InaccessibleImage
Has anyone tried this and any idea why it fails even though TokenCredential used. Please note that this TokenCredential works with ACR and is capable of pulling and pushing images, it's not working with ACI though.




