Error creating ACI with PowerShell

Sandro Francisco 26 Reputation points
2022-11-22T16:40:13.907+00:00

Hello,

I got an error while trying to deploy an ACI with PowerShell. I've followed the guide on the microsoft quickstart page (link), and while running the command "New-AzContainerGroup -ResourceGroupName myResourceGroup -Name mycontainer -Image mcr.microsoft.com/azuredocs/aci-helloworld:latest -OsType Windows -DnsNameLabel aci-demo-win", i get the following error:

"New-AzContainerGroup: Cannot process argument transformation on parameter 'ImageRegistryCredential'. Cannot convert value "mcr.microsoft.com/azuredocs/aci-helloworld:latest" to type "Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.IImageRegistryCredential[]". Error: "Cannot convert the "mcr.microsoft.com/azuredocs/aci-helloworld:latest" value of type "System.String" to type "Microsoft.Azure.PowerShell.Cmdlets.ContainerInstance.Models.Api20210901.IImageRegistryCredential"."
"

I've tried creating the container using Azure CLI and the portal and it worked perfectly, i'm only getting the error using PowerShell.

Thank you,
Sandro

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
635 questions
0 comments No comments
{count} vote

Accepted answer
  1. KarishmaTiwari-MSFT 18,442 Reputation points Microsoft Employee
    2022-11-22T17:15:03.577+00:00

    Hello @Sandro Francisco ,
    It looks like the documentation is not updated and missing the creation of container instance.

    Please try the example provided below, which states creation of container instance first using New-AzContainerInstanceObject and then creating Container group.

    https://learn.microsoft.com/en-us/powershell/module/az.containerinstance/new-azcontainergroup?view=azps-9.1.0#example-1-create-a-container-group-with-a-container-instance-and-request-a-public-ip-address-with-opening-ports

    $port1 = New-AzContainerInstancePortObject -Port 8000 -Protocol TCP  
    $port2 = New-AzContainerInstancePortObject -Port 8001 -Protocol TCP  
    $container = New-AzContainerInstanceObject -Name test-container -Image nginx -RequestCpu 1 -RequestMemoryInGb 1.5 -Port @($port1, $port2)  
    $containerGroup = New-AzContainerGroup -ResourceGroupName test-rg -Name test-cg -Location eastus -Container $container -OsType Linux -RestartPolicy "Never" -IpAddressType Public  
    

    I have also reached out to the document owner to ensure that the Quickstart: Deploy a container instance in Azure using Azure PowerShell document is updated.

    If you are still seeing difficulties creating ACI with PowerShell, let me know in the comments below and I can further investigate/engage with the right teams to ensure your query is resolved.

    ----------

    If this answers your query, do click “Accept the answer” and Up-Vote for the same, which might be beneficial to other community members reading this thread.
    And, if you have any further query do let us know in the comments.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Michael Taylor 48,046 Reputation points
    2022-11-22T17:25:23.793+00:00

    The docs on this cmdlet are not very good IMO. I would recommend that you provide feedback to the doc team to update this once you have it working.

    Given just the error I notice that it is talking about ImageRegistryCredential parameter which you aren't passing at all. This leads me to believe either it is using a default value which is not valid or it is misunderstanding one of your arguments. In the docs it notes that you need to create a hashtable to set this parameter but I don't see any examples to know exactly what that might look like.

    Additionally the docs use the Image parameter but only with what looks like a prefixed list of values and the entire parameter isn't documented. But if you look in the Notes section the very first item does mention setting that value but as part of a different parameter and, again, using a hash table. So whether the Image parameter is valid for custom images or not I'm not sure.

    The easiest thing to start with might be to wrap your image argument in single quotes so it sees it as a string just in case it is misinterpreting it. The second step would be to add the ImageRegistryCredential parameter and set it to ensure it is using the correct value.

    Otherwise I think you're going to have to post to the Github repo to get help on this particular error.