我具有以下powershell命令,该命令创建具有1个容器实例的Azure容器组:
az container create \
-g $(ResourceGroup) \
--name $(ContainerName) \
--image $(DockerImage) \
--cpu 2 --memory 8 \
--restart-policy OnFailure \
--vnet $(VNet) \
--subnet $(VNetSubnet) \
--registry-username $(RepositoryUserName) \
--registry-password $(RepositoryPassword)
基于此sample code,我正在尝试使用.NET客户端库执行相同的操作:
var containerGroup = _azure.ContainerGroups
.Define(agentName)
.WithRegion(resourceGroup.Region)
.WithExistingResourceGroup(resourceGroup.Name)
.WithLinux()
.WithPrivateImageRegistry("xxx.azurecr.io", "xxx", "xxx")
.WithoutVolume()
.DefineContainerInstance(agentName)
.WithImage(args.DockerImageName)
.WithExternalTcpPort(80)
.WithCpuCoreCount(args.CpuCoreCount)
.WithMemorySizeInGB(args.MemorySizeInGB)
.Attach()
.WithTags(tags)
.WithRestartPolicy(ContainerGroupRestartPolicy.Always)
.CreateAsync()
但是我找不到设置vnet和子网的方法。如何使用C#做到这一点?
答案 0 :(得分:0)
不确定,但是看来您无法通过C#做到这一点。可能是因为它只是Azure Container Instance的预览版。您可以看到所有可以在The entirety of the Azure Container Instance service container group definition中定义的内容。
或者您可以通过Azure REST API创建它。请参见Container Groups - Create Or Update,您可以配置属性networkProfile以在vnet中创建容器组。