2
votes

I have the following powershell command that creates an Azure container group with 1 container instance:

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)

I'm trying to do the same using the .NET Client Libraries, based on this sample code:

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()

But I can't find a way to set the vnet and subnet. How to do it using C#?

1
I still don't understand how to set the network profile using the fluent API, I have the impression it's not possible to do it with the current version - but thanks anyway @4c74356b41.Rui Jarimba
yeah, i didnt use c# sdk, so cant really help4c74356b41
two years left - still not possible (c) Microsoftcortisol
@cortisol FYI we stopped using ACI, we moved all our containers to AKS.Rui Jarimba

1 Answers

1
votes

Not sure, but it seems there you cannot do that through C#. Maybe because it is just a preview version of Azure Container Instance. You can see all that you can define in The entirety of the Azure Container Instance service container group definition.

Or you can create it through Azure REST API. See Container Groups - Create Or Update and you can config the property networkProfile to make the container group in a vnet.