我有以下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)
基于此示例代码,我正在尝试使用.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#做到这一点?
不确定,但是看来您无法通过C#做到这一点。也许是因为它只是Azure容器实例的预览版。您可以在“ Azure容器实例服务”容器组定义的全部中看到所有可以定义的内容。
或者,您可以通过Azure REST API创建它。请参阅容器组-创建或更新,您可以配置属性networkProfile以在vnet中创建容器组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句