加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

使用Azure容器注册表从C#创建新的Azure容器实例

发布时间:2020-12-14 04:26:29 所属栏目:Windows 来源:网络整理
导读:我创建了一个Azure容器注册表,并将自定义ACI上传到注册表 – 没问题 – 一切都按预期工作.我尝试使用Azure门户从映像创建容器实例,并且没有问题 – 但是 – 当我想使用Microsoft Azure管理容器实例Fluent API使用C#自动化时,我遇到问题,即使我感觉我已经遍布
我创建了一个Azure容器注册表,并将自定义ACI上传到注册表 – 没问题 – 一切都按预期工作.我尝试使用Azure门户从映像创建容器实例,并且没有问题 – 但是 – 当我想使用Microsoft Azure管理容器实例Fluent API使用C#自动化时,我遇到问题,即使我感觉我已经遍布互联网和设置,寻找隐藏的障碍物,我一直没有找到太多的帮助.

我的代码如下:

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:’无法访问容器组’mytestgroup’中的图像’mytestimage / latest’.请检查图像和注册表凭据.

我尝试了几件事;

>使用docker login测试凭据 – 没问题.
>用docker拉图像拉mytestreg.azurecr.io/mytestimage – 没问题.
>使用WithPublicImageRegistryOnly交换WithPrivateImageRegistry并在WithImage中使用debian – 按意图工作 – 没问题.
>从图像名称中删除最新标记 – 仍然无法正常工作.

我不知道为什么私有注册表的凭据不起作用 – 我直接从Azure门户复制/粘贴以避免拼写错误,尝试手动输入等.

使用Fiddler检查流量并未发现任何有趣的内容,除了上述异常消息直接从Azure Management API返回.

我遗失的显而易见的事情是什么?

解决方法

上面的答案(即使用完整的azure注册服务器名称):

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

似乎是解决方案的一部分,但即使有了这种改变,我仍然看到了这个错误.通过网络上的其他示例(https://github.com/Azure-Samples/aci-dotnet-create-container-groups-using-private-registry/blob/master/Program.cs)查看我需要的内容,我将azure身份验证更改为:

azure = Azure.Authenticate(authFilePath).WithDefaultSubscription();

至:

AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromFile(authFilePath);
azure = Azure
    .Configure()
    .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
    .Authenticate(credentials)
    .WithDefaultSubscription();

随着这种变化,事情现在正在发挥作用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读