New-AzContainerGroup

Creates a container group.

Syntax

New-AzContainerGroup
   [-ResourceGroupName] <String>
   [-Name] <String>
   [-Image] <String>
   [-RegistryCredential <PSCredential>]
   [-Location <String>]
   [-AssignIdentity]
   [-OsType <String>]
   [-RestartPolicy <String>]
   [-Cpu <Int32>]
   [-MemoryInGB <Double>]
   [-IpAddressType <String>]
   [-DnsNameLabel <String>]
   [-Port <Int32[]>]
   [-Command <String>]
   [-EnvironmentVariable <Hashtable>]
   [-RegistryServerDomain <String>]
   [-Tag <Hashtable>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-AzContainerGroup
   [-ResourceGroupName] <String>
   [-Name] <String>
   [-Image] <String>
   [-RegistryCredential <PSCredential>]
   -AzureFileVolumeShareName <String>
   -AzureFileVolumeAccountCredential <PSCredential>
   -AzureFileVolumeMountPath <String>
   [-Location <String>]
   [-AssignIdentity]
   [-OsType <String>]
   [-RestartPolicy <String>]
   [-Cpu <Int32>]
   [-MemoryInGB <Double>]
   [-IpAddressType <String>]
   [-DnsNameLabel <String>]
   [-Port <Int32[]>]
   [-Command <String>]
   [-EnvironmentVariable <Hashtable>]
   [-RegistryServerDomain <String>]
   [-Tag <Hashtable>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-AzContainerGroup
   [-ResourceGroupName] <String>
   [-Name] <String>
   [-Image] <String>
   [-RegistryCredential <PSCredential>]
   -AzureFileVolumeShareName <String>
   -AzureFileVolumeAccountCredential <PSCredential>
   -AzureFileVolumeMountPath <String>
   [-Location <String>]
   -IdentityType <ResourceIdentityType>
   [-IdentityId <String[]>]
   [-OsType <String>]
   [-RestartPolicy <String>]
   [-Cpu <Int32>]
   [-MemoryInGB <Double>]
   [-IpAddressType <String>]
   [-DnsNameLabel <String>]
   [-Port <Int32[]>]
   [-Command <String>]
   [-EnvironmentVariable <Hashtable>]
   [-RegistryServerDomain <String>]
   [-Tag <Hashtable>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-AzContainerGroup
   [-ResourceGroupName] <String>
   [-Name] <String>
   [-Image] <String>
   [-RegistryCredential <PSCredential>]
   [-Location <String>]
   -IdentityType <ResourceIdentityType>
   [-IdentityId <String[]>]
   [-OsType <String>]
   [-RestartPolicy <String>]
   [-Cpu <Int32>]
   [-MemoryInGB <Double>]
   [-IpAddressType <String>]
   [-DnsNameLabel <String>]
   [-Port <Int32[]>]
   [-Command <String>]
   [-EnvironmentVariable <Hashtable>]
   [-RegistryServerDomain <String>]
   [-Tag <Hashtable>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

The New-AzContainerGroup cmdlets creates a container group.

Examples

Example 1

PS C:\> New-AzContainerGroup -ResourceGroupName demo -Name mycontainer -Image nginx -OsType Linux -IpAddressType Public -Port @(8000)

ResourceGroupName        : demo
Id                       : /subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/demo/providers/Microsoft.ContainerInstance/containerGroups/mycontainer
Name                     : mycontainer
Type                     : Microsoft.ContainerInstance/containerGroups
Location                 : westus
Tags                     :
ProvisioningState        : Creating
Containers               : {mycontainer}
ImageRegistryCredentials :
RestartPolicy            :
IpAddress                : 13.88.10.240
Ports                    : {8000}
OsType                   : Linux
Volumes                  :
State                    : Running
Events                   : {}

This commands creates a container group using latest nginx image and requests a public IP address with opening port 8000.

Example 2

PS C:\> New-AzContainerGroup -ResourceGroupName demo -Name mycontainer -Image alpine -OsType Linux -Command "/bin/sh -c myscript.sh" -EnvironmentVariable @{"env1"="value1";"env2"="value2"}

ResourceGroupName        : demo
Id                       : /subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/demo/providers/Microsoft.ContainerInstance/containerGroups/mycontainer
Name                     : mycontainer
Type                     : Microsoft.ContainerInstance/containerGroups
Location                 : westus
Tags                     :
ProvisioningState        : Creating
Containers               : {mycontainer}
ImageRegistryCredentials :
RestartPolicy            :
IpAddress                :
Ports                    :
OsType                   : Linux
Volumes                  :
State                    : Running
Events                   : {}

This commands creates a container group and runs a custom script inside the container.

Example 3: Creates a run-to-completion container group.

PS C:\> New-AzContainerGroup -ResourceGroupName demo -Name mycontainer -Image alpine -OsType Linux -Command "echo hello" -RestartPolicy Never

ResourceGroupName        : demo
Id                       : /subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/demo/providers/Microsoft.ContainerInstance/containerGroups/mycontainer
Name                     : mycontainer
Type                     : Microsoft.ContainerInstance/containerGroups
Location                 : westus
Tags                     :
ProvisioningState        : Creating
Containers               : {mycontainer}
ImageRegistryCredentials :
RestartPolicy            :
IpAddress                :
Ports                    :
OsType                   : Linux
Volumes                  :
State                    : Running
Events                   : {}

This commands creates a container group which prints out 'hello' and stops.

Example 4: Creates a container group using image in Azure Container Registry

PS C:\> $secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
PS C:\> $mycred = New-Object System.Management.Automation.PSCredential ("myacr", $secpasswd)
PS C:\> New-AzContainerGroup -ResourceGroupName demo -Name mycontainer -Image myacr.azurecr.io/nginx:latest -IpAddressType Public -RegistryCredential $mycred

ResourceGroupName        : demo
Id                       : /subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/demo/providers/Microsoft.ContainerInstance/containerGroups/mycontainer
Name                     : mycontainer
Type                     : Microsoft.ContainerInstance/containerGroups
Location                 : westus
Tags                     :
ProvisioningState        : Creating
Containers               : {mycontainer}
ImageRegistryCredentials : {myacr}
RestartPolicy            :
IpAddress                : 13.88.10.240
Ports                    : {80}
OsType                   : Linux
Volumes                  :
State                    : Running
Events                   : {}

This commands creates a container group using a nginx image in Azure Container Registry.

Example 5: Creates a container group using image in custom container image registry

PS C:\> $secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
PS C:\> $mycred = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)
PS C:\> New-AzContainerGroup -ResourceGroupName MyResourceGroup -Name MyContainer -Image myserver.com/myimage:latest -RegistryServer myserver.com -RegistryCredential $mycred

ResourceGroupName        : demo
Id                       : /subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/demo/providers/Microsoft.ContainerInstance/containerGroups/mycontainer
Name                     : mycontainer
Type                     : Microsoft.ContainerInstance/containerGroups
Location                 : westus
Tags                     :
ProvisioningState        : Creating
Containers               : {mycontainer}
ImageRegistryCredentials : {myserver.com}
RestartPolicy            :
IpAddress                : 13.88.10.240
Ports                    : {80}
OsType                   : Linux
Volumes                  :
State                    : Running
Events                   : {}

This commands creates a container group using a custom image from a custom container image registry.

Example 6: Creates a container group that mounts Azure File volume

PS C:\> $secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
PS C:\> $mycred = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)
PS C:\> New-AzContainerGroup -ResourceGroupName MyResourceGroup -Name MyContainer -Image alpine -AzFileVolumeShareName myshare -AzFileVolumeAccountKey $mycred -AzFileVolumeMountPath /mnt/azfile

ResourceGroupName        : demo
Id                       : /subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/demo/providers/Microsoft.ContainerInstance/containerGroups/mycontainer
Name                     : mycontainer
Type                     : Microsoft.ContainerInstance/containerGroups
Location                 : westus
Tags                     :
ProvisioningState        : Creating
Containers               : {mycontainer}
ImageRegistryCredentials : {myserver.com}
RestartPolicy            :
IpAddress                : 13.88.10.240
Ports                    : {80}
OsType                   : Linux
Volumes                  : {AzureFile}
State                    : Running
Events                   : {}

This commands creates a container group that mounts the provided Azure File share to /mnt/azfile.

Example 7

PS C:\> New-AzContainerGroup -ResourceGroupName demo -Name mycontainer -Image nginx -OsType Linux -IpAddressType Public -Port @(8000) -AssignIdentity

ResourceGroupName        : demo
Id                       : /subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/demo/providers/Microsoft.ContainerInstance/containerGroups/mycontainer
Name                     : mycontainer
Type                     : Microsoft.ContainerInstance/containerGroups
Location                 : westus
Tags                     :
ProvisioningState        : Creating
Containers               : {mycontainer}
ImageRegistryCredentials :
RestartPolicy            :
IpAddress                : 13.88.10.240
Ports                    : {8000}
OsType                   : Linux
Volumes                  :
State                    : Running
Events                   : {}
Identity                 : Microsoft.Azure.Management.ContainerInstance.Models.ContainerGroupIdentity

This commands creates a container group with system assigned identity using latest nginx image and requests a public IP address with opening port 8000.

Example 8

PS C:\> New-AzContainerGroup -ResourceGroupName demo -Name mycontainer -Image nginx -OsType Linux -IpAddressType Public -Port @(8000) -IdentityType SystemAssignedUserAssigned -IdentityId /subscriptions/<subscriptionId>/resourceGroups/<resourceGroup>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<UserIdentityName>

ResourceGroupName        : demo
Id                       : /subscriptions/ae43b1e3-c35d-4c8c-bc0d-f148b4c52b78/resourceGroups/demo/providers/Microsoft.ContainerInstance/containerGroups/mycontainer
Name                     : mycontainer
Type                     : Microsoft.ContainerInstance/containerGroups
Location                 : westus
Tags                     :
ProvisioningState        : Creating
Containers               : {mycontainer}
ImageRegistryCredentials :
RestartPolicy            :
IpAddress                : 13.88.10.240
Ports                    : {8000}
OsType                   : Linux
Volumes                  :
State                    : Running
Events                   : {}
Identity                 : Microsoft.Azure.Management.ContainerInstance.Models.ContainerGroupIdentity

This commands creates a container group with system assigned and user assigned identity using latest nginx image and requests a public IP address with opening port 8000.

Parameters

-AssignIdentity

Enable system assigned identity

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-AzureFileVolumeAccountCredential

The storage account credential of the Azure File share to mount where the username is the storage account name and the key is the storage account key.

Type:PSCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-AzureFileVolumeMountPath

The mount path for the Azure File volume.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-AzureFileVolumeShareName

The name of the Azure File share to mount.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Command

The command to run in the container.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Cpu

The required CPU cores. Default: 1

Type:System.Nullable`1[System.Int32]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DnsNameLabel

The DNS name label for the IP address.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-EnvironmentVariable

The container environment variables.

Type:Hashtable
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-IdentityId

The user assigned identity IDs

Type:System.String[]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-IdentityType

The managed identity type

Type:ResourceIdentityType
Accepted values:SystemAssigned, UserAssigned, SystemAssignedUserAssigned, None
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Image

The container image.

Type:String
Position:2
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-IpAddressType

The IP address type.

Type:String
Accepted values:Public
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Location

The container group Location. Default to the location of the resource group.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-MemoryInGB

The required memory in GB. Default: 1.5

Type:System.Nullable`1[System.Double]
Aliases:Memory
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Name

The container group name.

Type:String
Position:1
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-OsType

The container OS type. Default: Linux

Type:String
Accepted values:Linux, Windows
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Port

The port(s) to open. Default: [80]

Type:System.Int32[]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-RegistryCredential

The custom container registry credential.

Type:PSCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-RegistryServerDomain

The custom container registry login server.

Type:String
Aliases:RegistryServer
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ResourceGroupName

The resource group name.

Type:String
Position:0
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-RestartPolicy

The container restart policy. Default: Always

Type:String
Accepted values:Always, Never, OnFailure
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Tag

{{Fill Tag Description}}

Type:Hashtable
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Inputs

String

System.String[]

Hashtable

Outputs

PSContainerGroup