你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
New-AzContainerGroup
创建或更新具有指定配置的容器组。
语法
New-AzContainerGroup
-Name <String>
-ResourceGroupName <String>
-Container <IContainer[]>
-Location <String>
[-SubscriptionId <String>]
[-DnsConfigNameServer <String[]>]
[-DnsConfigOption <String>]
[-DnsConfigSearchDomain <String>]
[-EncryptionPropertyKeyName <String>]
[-EncryptionPropertyKeyVersion <String>]
[-EncryptionPropertyVaultBaseUrl <String>]
[-IdentityType <ResourceIdentityType>]
[-IdentityUserAssignedIdentity <Hashtable>]
[-ImageRegistryCredential <IImageRegistryCredential[]>]
[-InitContainer <IInitContainerDefinition[]>]
[-IPAddressDnsNameLabel <String>]
[-IPAddressIP <String>]
[-IPAddressPort <IPort[]>]
[-IPAddressType <ContainerGroupIPAddressType>]
[-LogAnalyticLogType <LogAnalyticsLogType>]
[-LogAnalyticMetadata <Hashtable>]
[-LogAnalyticWorkspaceId <String>]
[-LogAnalyticWorkspaceKey <String>]
[-LogAnalyticWorkspaceResourceId <String>]
[-OSType <OperatingSystemTypes>]
[-Priority <String>]
[-RestartPolicy <ContainerGroupRestartPolicy>]
[-Sku <ContainerGroupSku>]
[-SubnetId <IContainerGroupSubnetId[]>]
[-Tag <Hashtable>]
[-Volume <IVolume[]>]
[-Zone <String[]>]
[-DefaultProfile <PSObject>]
[-AsJob]
[-NoWait]
[-Confirm]
[-WhatIf]
[<CommonParameters>]
说明
创建或更新具有指定配置的容器组。
示例
示例 1:使用容器实例创建容器组,并使用打开端口请求公共 IP 地址
$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
Location Name Zone ResourceGroupName
-------- ---- ---- -----------------
eastus test-cg test-rg
此命令创建包含容器实例的容器组,该容器实例的映像是最新的 nginx,并使用打开端口 8000 和 8001 请求公共 IP 地址。
示例 2:创建容器组并在容器内运行自定义脚本。
$env1 = New-AzContainerInstanceEnvironmentVariableObject -Name "env1" -Value "value1"
$env2 = New-AzContainerInstanceEnvironmentVariableObject -Name "env2" -SecureValue (ConvertTo-SecureString -String "value2" -AsPlainText -Force)
$container = New-AzContainerInstanceObject -Name test-container -Image alpine -Command "/bin/sh -c myscript.sh" -EnvironmentVariable @($env1, $env2)
$containerGroup = New-AzContainerGroup -ResourceGroupName test-rg -Name test-cg -Location eastus -Container $container -OsType Linux
Location Name Zone ResourceGroupName
-------- ---- ---- -----------------
eastus test-cg test-rg
此命令将创建容器组并在容器内运行自定义脚本。
示例 3:创建运行到完成容器组
$container = New-AzContainerInstanceObject -Name test-container -Image alpine -Command "echo hello"
$containerGroup = New-AzContainerGroup -ResourceGroupName test-rg -Name test-cg -Location eastus -Container $container -OsType Linux
Location Name Zone ResourceGroupName
-------- ---- ---- -----------------
eastus test-cg test-rg
此命令将创建一个容器组,用于输出“hello”并停止。
示例 4:在 Azure 容器注册表 中使用映像 nginx 创建包含容器实例的容器组
$container = New-AzContainerInstanceObject -Name test-container -Image myacr.azurecr.io/nginx:latest
$imageRegistryCredential = New-AzContainerGroupImageRegistryCredentialObject -Server "myacr.azurecr.io" -Username "username" -Password (ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force)
$containerGroup = New-AzContainerGroup -ResourceGroupName test-rg -Name test-cg -Location eastus -Container $container -ImageRegistryCredential $imageRegistryCredential
Location Name Zone ResourceGroupName
-------- ---- ---- -----------------
eastus test-cg test-rg
此命令创建包含容器实例的容器组,该容器实例的映像为 Azure 容器注册表 中的 nginx。
示例 5:在自定义容器映像注册表中使用映像 nginx 创建包含容器实例的容器组
$container = New-AzContainerInstanceObject -Name test-container -Image myserver.com/nginx:latest
$imageRegistryCredential = New-AzContainerGroupImageRegistryCredentialObject -Server "myserver.com" -Username "username" -Password (ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force)
$containerGroup = New-AzContainerGroup -ResourceGroupName test-rg -Name test-cg -Location eastus -Container $container -ImageRegistryCredential $imageRegistryCredential
Location Name Zone ResourceGroupName
-------- ---- ---- -----------------
eastus test-cg test-rg
此命令使用容器实例创建容器组,该容器实例的映像是自定义容器映像注册表中的自定义映像。
示例 6:创建装载 Azure 文件卷的容器组
$volume = New-AzContainerGroupVolumeObject -Name "myvolume" -AzureFileShareName "myshare" -AzureFileStorageAccountName "username" -AzureFileStorageAccountKey (ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force)
$mount = New-AzContainerInstanceVolumeMountObject -MountPath "/aci/logs" -Name "myvolume"
$container = New-AzContainerInstanceObject -Name test-container -Image alpine -VolumeMount $mount
$containerGroup = New-AzContainerGroup -ResourceGroupName test-rg -Name test-cg -Location eastus -Container $container -Volume $volume
Location Name Zone ResourceGroupName
-------- ---- ---- -----------------
eastus test-cg test-rg
此命令使用容器实例创建容器组,该容器实例的映像是自定义容器映像注册表中的自定义映像。
示例 7:创建具有系统分配标识和用户分配标识的容器组
$container = New-AzContainerInstanceObject -Name test-container -Image alpine
$containerGroup = New-AzContainerGroup -ResourceGroupName test-rg -Name test-cg -Location eastus -Container $container -IdentityType "SystemAssigned, UserAssigned" -IdentityUserAssignedIdentity @{"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}" = @{}}
Location Name Zone ResourceGroupName
-------- ---- ---- -----------------
eastus test-cg test-rg
此命令创建一个容器组,其中包含系统分配的标识和用户分配的标识。
参数
-AsJob
以作业身份运行命令
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Confirm
提示你在运行 cmdlet 之前进行确认。
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Container
容器组中的容器。 若要构造,请参阅 CONTAINER 属性的 NOTES 部分并创建哈希表。
Type: | IContainer[] |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DefaultProfile
用于与 Azure 通信的凭据、帐户、租户和订阅。
Type: | PSObject |
Aliases: | AzureRMContext, AzureCredential |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DnsConfigNameServer
容器组的 DNS 服务器。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DnsConfigOption
容器组的 DNS 选项。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DnsConfigSearchDomain
容器组中主机名查找的 DNS 搜索域。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-EncryptionPropertyKeyName
加密密钥名称。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-EncryptionPropertyKeyVersion
加密密钥版本。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-EncryptionPropertyVaultBaseUrl
密钥保管库基础 URL。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-IdentityType
容器组使用的标识类型。 类型“SystemAssigned ,UserAssigned”包含隐式创建的标识和一组用户分配的标识。 类型“None”删除容器组中的所有标识。
Type: | ResourceIdentityType |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-IdentityUserAssignedIdentity
与容器组关联的用户标识列表。 用户标识字典密钥引用的格式为 ARM 资源 ID:“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。
Type: | Hashtable |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ImageRegistryCredential
创建容器组所依据的映像注册表凭据。 若要构造,请参阅 IMAGEREGISTRYCREDENTIAL 属性的 NOTES 部分,并创建哈希表。
Type: | IImageRegistryCredential[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-InitContainer
容器组的 Init 容器。 若要构造,请参阅 INITCONTAINER 属性的 NOTES 部分并创建哈希表。
Type: | IInitContainerDefinition[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-IPAddressDnsNameLabel
IP 的 DNS 名称标签。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-IPAddressIP
向公共 Internet 公开的 IP。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-IPAddressPort
容器组上公开的端口列表。 若要构造,请参阅 IPADDRESSPORT 属性的 NOTES 部分并创建哈希表。
Type: | IPort[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-IPAddressType
指定 IP 是否向公共 Internet 或专用 VNET 公开。
Type: | ContainerGroupIPAddressType |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Location
资源位置。
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-LogAnalyticLogType
要使用的日志类型。
Type: | LogAnalyticsLogType |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-LogAnalyticMetadata
Log Analytics 的元数据。
Type: | Hashtable |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-LogAnalyticWorkspaceId
Log Analytics 的工作区 ID
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-LogAnalyticWorkspaceKey
Log Analytics 的工作区键
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-LogAnalyticWorkspaceResourceId
Log Analytics 的工作区资源 ID
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Name
容器组的名称。
Type: | String |
Aliases: | ContainerGroupName |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-NoWait
异步运行命令
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-OSType
容器组中容器所需的操作系统类型。
Type: | OperatingSystemTypes |
Position: | Named |
Default value: | "Linux" |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Priority
容器组的优先级。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ResourceGroupName
资源组的名称。
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-RestartPolicy
容器组中所有容器的重启策略。
Always
始终重启 -OnFailure
失败时重启 -Never
从不重启
Type: | ContainerGroupRestartPolicy |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Sku
容器组的 SKU。
Type: | ContainerGroupSku |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-SubnetId
容器组的子网资源 ID。 若要构造,请参阅 SUBNETID 属性的 NOTES 部分并创建哈希表。
Type: | IContainerGroupSubnetId[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-SubscriptionId
唯一标识 Microsoft Azure 订阅的订阅凭据。 此订阅 ID 是每个服务调用的 URI 的一部分。
Type: | String |
Position: | Named |
Default value: | (Get-AzContext).Subscription.Id |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Tag
资源标记。
Type: | Hashtable |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Volume
此容器组中的容器可以装载的卷列表。 若要构造,请参阅 VOLUME 属性的 NOTES 部分并创建哈希表。
Type: | IVolume[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WhatIf
显示运行该 cmdlet 时会发生什么情况。 cmdlet 未运行。
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Zone
容器组的区域。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
输出
备注
别名
复杂参数属性
若要创建下面所述的参数,请构造一个包含相应属性的哈希表。 有关哈希表的信息,请运行 Get-Help about_Hash_Tables。
CONTAINER <IContainer[]>
:容器组中的容器。
Image <String>
:用于创建容器实例的映像的名称。Name <String>
:容器实例的用户提供的名称。RequestCpu <Double>
:此容器实例的 CPU 请求。RequestMemoryInGb <Double>
:此容器实例的内存请求(以 GB 为单位)。[Command <String[]>]
:要以 exec 形式在容器实例中执行的命令。[EnvironmentVariable <IEnvironmentVariable[]>]
:在容器实例中设置的环境变量。Name <String>
:环境变量的名称。[SecureValue <String>]
:安全环境变量的值。[Value <String>]
:环境变量的值。
[LimitCpu <Double?>]
:此容器实例的 CPU 限制。[LimitMemoryInGb <Double?>]
:此容器实例的内存限制(以 GB 为单位)。[LimitsGpuCount <Int32?>]
:GPU 资源的计数。[LimitsGpuSku <GpuSku?>]
:GPU 资源的 SKU。[LivenessProbeExecCommand <String[]>]
:在容器中执行的命令。[LivenessProbeFailureThreshold <Int32?>]
:失败阈值。[LivenessProbeHttpGetHttpHeader <IHttpHeader[]>]
:HTTP 标头。[Name <String>]
:标头名称。[Value <String>]
:标头值。
[LivenessProbeHttpGetPath <String>]
:探测的路径。[LivenessProbeHttpGetPort <Int32?>]
:要探测的端口号。[LivenessProbeHttpGetScheme <Scheme?>]
:方案。[LivenessProbeInitialDelaySecond <Int32?>]
:初始延迟秒。[LivenessProbePeriodSecond <Int32?>]
:时间段秒。[LivenessProbeSuccessThreshold <Int32?>]
:成功阈值。[LivenessProbeTimeoutSecond <Int32?>]
:超时秒。[Port <IContainerPort[]>]
:容器实例上公开的端口。Port <Int32>
:容器组中公开的端口号。[Protocol <ContainerNetworkProtocol?>]
:与端口关联的协议。
[ReadinessProbeExecCommand <String[]>]
:在容器中执行的命令。[ReadinessProbeFailureThreshold <Int32?>]
:失败阈值。[ReadinessProbeHttpGetHttpHeader <IHttpHeader[]>]
:HTTP 标头。[ReadinessProbeHttpGetPath <String>]
:探测的路径。[ReadinessProbeHttpGetPort <Int32?>]
:要探测的端口号。[ReadinessProbeHttpGetScheme <Scheme?>]
:方案。[ReadinessProbeInitialDelaySecond <Int32?>]
:初始延迟秒。[ReadinessProbePeriodSecond <Int32?>]
:时间段秒。[ReadinessProbeSuccessThreshold <Int32?>]
:成功阈值。[ReadinessProbeTimeoutSecond <Int32?>]
:超时秒。[RequestsGpuCount <Int32?>]
:GPU 资源的计数。[RequestsGpuSku <GpuSku?>]
:GPU 资源的 SKU。[VolumeMount <IVolumeMount[]>]
:可用于容器实例的卷装载。MountPath <String>
:容器中应装载卷的路径。 不得包含冒号 (:)。Name <String>
:卷装载的名称。[ReadOnly <Boolean?>]
:指示卷装载是否为只读的标志。
IMAGEREGISTRYCREDENTIAL <IImageRegistryCredential[]>
:从中创建容器组的映像注册表凭据。
Server <String>
:没有协议的 Docker 映像注册表服务器,例如“http”和“https”。[Identity <String>]
:专用注册表的标识。[IdentityUrl <String>]
:专用注册表的标识 URL。[Password <String>]
:专用注册表的密码。[Username <String>]
:专用注册表的用户名。
INITCONTAINER <IInitContainerDefinition[]>
:容器组的初始化容器。
Name <String>
:init 容器的名称。[Command <String[]>]
:要以 exec 形式在 init 容器中执行的命令。[EnvironmentVariable <IEnvironmentVariable[]>]
:在 init 容器中设置的环境变量。Name <String>
:环境变量的名称。[SecureValue <String>]
:安全环境变量的值。[Value <String>]
:环境变量的值。
[Image <String>]
:init 容器的图像。[VolumeMount <IVolumeMount[]>]
:可用于 init 容器的卷装载。MountPath <String>
:容器中应装载卷的路径。 不得包含冒号 (:)。Name <String>
:卷装载的名称。[ReadOnly <Boolean?>]
:指示卷装载是否为只读的标志。
IPADDRESSPORT <IPort[]>
:容器组上公开的端口列表。
Port1 <Int32>
:端口号。[Protocol <ContainerGroupNetworkProtocol?>]
:与端口关联的协议。
SUBNETID <IContainerGroupSubnetId[]>
:容器组的子网资源 ID。
Id <String>
:虚拟网络和子网的资源 ID。[Name <String>]
:子网的友好名称。
VOLUME <IVolume[]>
:此容器组中的容器可以装载的卷列表。
Name <String>
:卷的名称。[AzureFileReadOnly <Boolean?>]
:指示装载为卷的 Azure 文件共享是否为只读的标志。[AzureFileShareName <String>]
:要装载为卷的 Azure 文件共享的名称。[AzureFileStorageAccountKey <String>]
:用于访问 Azure 文件共享的存储帐户访问密钥。[AzureFileStorageAccountName <String>]
:包含 Azure 文件共享的存储帐户的名称。[EmptyDir <IVolumeEmptyDir>]
:空目录卷。[(Any) <Object>]
:这表示可以将任何属性添加到此对象。
[GitRepoDirectory <String>]
:目标目录名称。 不得包含“..”,也不能以其开头。 如果提供了“.”,则卷目录将是 Git 存储库。 否则,卷将包含子目录中具有给定名称的 Git 存储库(如果已指定)。[GitRepoRepository <String>]
:存储库 URL[GitRepoRevision <String>]
:提交指定修订的哈希。[Secret <ISecretVolume>]
:机密卷。[(Any) <String>]
:这表示可以将任何属性添加到此对象。
反馈
https://aka.ms/ContentUserFeedback。
即将推出:在整个 2024 年,我们将逐步取消以“GitHub 问题”作为内容的反馈机制,并将其替换为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈