我创建了一个 Azure 容器注册表,并将自定义 ACI 上传到注册表 - 没问题 - 一切都按预期工作。我尝试使用 Azure 门户从映像创建容器实例,也没有问题 - 但是 - 当我想使用 C# 和 Microsoft Azure Management Container Instance Fluent API 自动执行操作时,我遇到了问题,即使我感觉自己翻遍了互联网和设置,寻找隐藏的障碍,一直没能找到多少帮助。
我的代码如下:
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();
上面的代码一直给我一个例外:
Microsoft.Rest.Azure.CloudException: 'The image 'mytestimage/latest' in container group 'mytestgroup' is not accessible. Please check the image and registry credential.'
我尝试了几件事;
- 测试凭据
docker login
- 没问题。 - 拉图像
docker pull mytestreg.azurecr.io/mytestimage
- 没问题。 - 交换
WithPrivateImageRegistry
并WithPublicImageRegistryOnly
仅使用debian
inWithImage
- 按预期工作 - 没问题。 - 将标签留在
latest
图像名称之外 - 仍然不起作用。
我不知道为什么私有注册表的凭据不起作用 - 我一直在直接从 Azure 门户复制/粘贴以避免拼写错误,尝试手动输入等。
使用 Fiddler 检查流量并没有发现任何有趣的信息,除了上述异常消息是直接从 Azure 管理 API 返回的。
我缺少什么明显的东西?