你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

az container

注意

此命令组具有在 Azure CLI 和至少一个扩展中定义的命令。 安装每个扩展,使其受益于其扩展功能。 详细了解扩展。

管理Azure 容器实例。

命令

名称 说明 类型 状态
az container app

用于管理Azure 容器实例应用的命令。

扩展 预览
az container app up

使用 GitHub Actions 部署到Azure 容器实例。

分机 预览
az container attach

将本地标准输出和错误流附加到容器组中的容器。 此命令在容器启动期间提供诊断信息。 启动容器后,它会将 STDOUT 和 STDERR 流式传输到本地控制台。

核心 GA
az container create

创建容器组。

核心 GA
az container delete

删除容器组。

核心 GA
az container exec

从容器组的正在运行的容器内执行命令。

核心 GA
az container export

以 yaml 格式导出容器组。

核心 GA
az container list

列出容器组。

核心 GA
az container logs

检查容器组中容器的日志。

核心 GA
az container restart

重启容器组中的所有容器。

核心 GA
az container show

获取容器组的详细信息。

核心 GA
az container start

启动容器组中的所有容器。

核心 GA
az container stop

停止容器组中的所有容器。

核心 GA

az container attach

将本地标准输出和错误流附加到容器组中的容器。 此命令在容器启动期间提供诊断信息。 启动容器后,它会将 STDOUT 和 STDERR 流式传输到本地控制台。

az container attach [--container-name]
                    [--ids]
                    [--name]
                    [--resource-group]
                    [--subscription]

示例

将本地标准输出和错误流附加到容器组中的容器。 (自动生成)

az container attach --name MyContainerGroup --resource-group MyResourceGroup

可选参数

--container-name

要附加到的容器。 如果省略,则会选择容器组中的第一个容器。

--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

容器组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az container create

创建容器组。

az container create --resource-group
                    [--acr-identity]
                    [--add-capabilities]
                    [--allow-escalation]
                    [--assign-identity]
                    [--azure-file-volume-account-key]
                    [--azure-file-volume-account-name]
                    [--azure-file-volume-mount-path]
                    [--azure-file-volume-share-name]
                    [--cce-policy]
                    [--command-line]
                    [--cpu]
                    [--dns-name-label]
                    [--drop-capabilities]
                    [--environment-variables]
                    [--file]
                    [--gitrepo-dir]
                    [--gitrepo-mount-path]
                    [--gitrepo-revision]
                    [--gitrepo-url]
                    [--image]
                    [--ip-address {Private, Public}]
                    [--location]
                    [--log-analytics-workspace]
                    [--log-analytics-workspace-key]
                    [--memory]
                    [--name]
                    [--no-wait]
                    [--os-type {Linux, Windows}]
                    [--ports]
                    [--priority]
                    [--privileged]
                    [--protocol {TCP, UDP}]
                    [--registry-login-server]
                    [--registry-password]
                    [--registry-username]
                    [--restart-policy {Always, Never, OnFailure}]
                    [--role]
                    [--run-as-group]
                    [--run-as-user]
                    [--scope]
                    [--seccomp-profile]
                    [--secrets]
                    [--secrets-mount-path]
                    [--secure-environment-variables]
                    [--sku]
                    [--subnet]
                    [--subnet-address-prefix]
                    [--vnet]
                    [--vnet-address-prefix]
                    [--vnet-name]
                    [--zone]

示例

在具有 1 核和 1Gb 内存的容器组中创建容器。

az container create -g MyResourceGroup --name myapp --image myimage:latest --cpu 1 --memory 1

在运行 Windows 的容器组中创建一个容器,其中包含 2 个核心和 3.5Gb 内存。

az container create -g MyResourceGroup --name mywinapp --image winappimage:latest --os-type Windows --cpu 2 --memory 3.5

在具有公共 IP 地址、端口和 DNS 名称标签的容器组中创建容器。

az container create -g MyResourceGroup --name myapp --image myimage:latest --ports 80 443 --dns-name-label contoso

在容器组中创建容器,该容器在启动时调用脚本。

az container create -g MyResourceGroup --name myapp --image myimage:latest --command-line "/bin/sh -c '/path to/myscript.sh'"

在运行命令并随后停止容器的容器组中创建容器。

az container create -g MyResourceGroup --name myapp --image myimage:latest --command-line "echo hello" --restart-policy Never

使用环境变量在容器组中创建容器。

az container create -g MyResourceGroup --name myapp --image myimage:latest --environment-variables key1=value1 key2=value2

使用Azure 容器注册表中的容器映像在容器组中创建容器。

az container create -g MyResourceGroup --name myapp --image myAcrRegistry.azurecr.io/myimage:latest --registry-password password

在将 Azure 文件共享装载为卷的容器组中创建容器。

az container create -g MyResourceGroup --name myapp --image myimage:latest --command-line "cat /mnt/azfile/myfile" --azure-file-volume-share-name myshare --azure-file-volume-account-name mystorageaccount --azure-file-volume-account-key mystoragekey --azure-file-volume-mount-path /mnt/azfile

在将 git 存储库装载为卷的容器组中创建容器。

az container create -g MyResourceGroup --name myapp --image myimage:latest --command-line "cat /mnt/gitrepo" --gitrepo-url https://github.com/user/myrepo.git --gitrepo-dir ./dir1 --gitrepo-mount-path /mnt/gitrepo

使用 yaml 文件在容器组中创建容器。

az container create -g MyResourceGroup -f containerGroup.yaml

使用 Log Analytics 从工作区名称创建容器组。

az container create -g MyResourceGroup --name myapp --log-analytics-workspace myworkspace

使用系统分配的标识创建容器组。

az container create -g MyResourceGroup --name myapp --image myimage:latest --assign-identity

使用系统分配的标识创建容器组。 该组将具有有权访问存储帐户的“参与者”角色。

az container create -g MyResourceGroup --name myapp --image myimage:latest --assign-identity --scope /subscriptions/99999999-1bf0-4dda-aec3-cb9272f09590/MyResourceGroup/myRG/providers/Microsoft.Storage/storageAccounts/storage1

创建具有用户分配标识的容器组。

az container create -g MyResourceGroup --name myapp --image myimage:latest --assign-identity  /subscriptions/mySubscriptionId/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID

使用系统和用户分配的标识创建容器组。

az container create -g MyResourceGroup --name myapp --image myimage:latest --assign-identity [system] /subscriptions/mySubscriptionId/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID

必需参数

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

可选参数

--acr-identity

有权访问容器注册表的标识。

--add-capabilities

要添加的安全上下文功能的列表。

--allow-escalation

允许进程能否获得比其父进程更多的特权。

默认值: False
--assign-identity

分配的标识的空间分隔列表。 分配的标识是用户分配的标识(资源 ID)和/或系统分配的标识('[系统]')。 有关详细信息,请参阅示例。

--azure-file-volume-account-key

用于访问 Azure 文件共享的存储帐户访问密钥。

--azure-file-volume-account-name

包含 Azure 文件共享的存储帐户的名称。

--azure-file-volume-mount-path

应装载 Azure 文件卷的容器中的路径。 不得包含冒号“:”。

--azure-file-volume-share-name

要以卷形式装载的 Azure 文件共享的名称。

--cce-policy

机密容器组的 CCE 策略。

--command-line

启动容器时要运行的命令行,例如“/bin/bash -c myscript.sh”。

--cpu

容器的所需 CPU 核心数,准确到一个小数位数。

默认值: 1
--dns-name-label

具有公共 IP 的容器组的 dns 名称标签。

--drop-capabilities

要删除的安全上下文功能的列表。

--environment-variables -e

容器的环境变量列表。 以“key=value”格式分隔的空间值。

--file -f

输入文件的路径。

--gitrepo-dir

git 存储库中的目标目录路径。 不得包含“..”。

默认值: .
--gitrepo-mount-path

应装载 git 存储库卷的容器中的路径。 不得包含冒号“:”。

--gitrepo-revision

指定修订的提交哈希。

--gitrepo-url

要装载为卷的 git 存储库的 URL。

--image

容器映像名称。

--ip-address

容器组的 IP 地址类型。

接受的值: Private, Public
--location -l

位置。 az account list-locations 中的值。 可以使用 az configure --defaults location=<location> 配置默认位置。

--log-analytics-workspace

Log Analytics 工作区名称或 ID。使用当前订阅或使用 --subscription 标志设置所需的订阅。

--log-analytics-workspace-key

Log Analytics 工作区密钥。

--memory

容器的所需内存(以 GB 为单位,精确到一个小数位)。

默认值: 1.5
--name -n

容器组的名称。

--no-wait

不等待长时间运行的操作完成。

默认值: False
--os-type

容器的 OS 类型。

接受的值: Linux, Windows
默认值: Linux
--ports

要打开的端口列表。 以空格分隔的端口列表。

默认值: [80]
--priority

容器组的优先级。

--privileged

用于确定容器权限是否提升为 Privileged 的标志。

默认值: False
--protocol

要使用的网络协议。

接受的值: TCP, UDP
--registry-login-server

容器映像注册表登录服务器。

--registry-password

用于登录容器映像注册表服务器的密码。

--registry-username

要在容器映像注册表服务器中登录的用户名。

--restart-policy

容器组中所有容器的重启策略。

接受的值: Always, Never, OnFailure
默认值: Always
--role

系统分配的标识将具有的角色名称或 ID。

默认值: Contributor
--run-as-group

设置容器的用户 UID。

--run-as-user

设置容器的用户 GID。

--scope

系统分配的标识可以访问的范围。

--seccomp-profile

包含 seccomp 配置文件中 JSON 内容的 base64 编码字符串。

--secrets

以“key=value”格式分隔的空间分隔机密。

--secrets-mount-path

应装载机密卷的容器中的路径。 不得包含冒号“:”。

--secure-environment-variables

容器的安全环境变量列表。 以“key=value”格式分隔的空间值。

--sku

容器组的 SKU。

--subnet

创建新 VNET 或引用现有 VNET 时子网的名称。 还可以按 ID 引用现有子网。

--subnet-address-prefix

以 CIDR 格式创建新 VNET 时要使用的子网 IP 地址前缀。

默认值: 10.0.0.0/24
--vnet

创建新 VNET 或引用现有 VNET 的名称。 还可以按 ID 引用现有 vnet。 这允许使用其他资源组中的 vnet。

--vnet-address-prefix

以 CIDR 格式创建新 VNET 时要使用的 IP 地址前缀。

默认值: 10.0.0.0/16
--vnet-name
已放弃

参数“vnet_name”已弃用,将在将来的版本中删除。 请改用“--vnet”。

创建新 VNET 或引用现有 VNET 的名称。

--zone

要放置容器组的区域。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az container delete

删除容器组。

az container delete [--ids]
                    [--name]
                    [--resource-group]
                    [--subscription]
                    [--yes]

示例

删除容器组。 (自动生成)

az container delete --name MyContainerGroup --resource-group MyResourceGroup

可选参数

--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

容器组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--yes -y

不提示确认。

默认值: False
全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az container exec

从容器组的正在运行的容器内执行命令。

最常见的用例是打开交互式 bash shell。 请参阅以下示例。

az container exec --exec-command
                  [--container-name]
                  [--ids]
                  [--name]
                  [--resource-group]
                  [--subscription]

示例

从 nginx 容器中流式传输 shell。

az container exec -g MyResourceGroup --name mynginx --container-name nginx --exec-command "/bin/bash"

必需参数

--exec-command

要从容器中运行的命令。

可选参数

--container-name

要在其中执行命令的容器名称。 对于只有一个容器的容器组,可以忽略这些容器。

--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

容器组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az container export

以 yaml 格式导出容器组。

az container export --file
                    [--ids]
                    [--name]
                    [--resource-group]
                    [--subscription]

示例

在 yaml 中导出容器组。

az container export -g MyResourceGroup --name mynginx -f output.yaml

必需参数

--file -f

导出容器组的文件路径。

可选参数

--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

容器组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az container list

列出容器组。

az container list [--resource-group]

可选参数

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az container logs

检查容器组中容器的日志。

az container logs [--container-name]
                  [--follow]
                  [--ids]
                  [--name]
                  [--resource-group]
                  [--subscription]

示例

检查容器组中容器的日志。 (自动生成)

az container logs --name MyContainerGroup --resource-group MyResourceGroup

可选参数

--container-name

要尾部日志的容器名称。 如果省略,则会选择容器组中的第一个容器。

--follow

指示流式传输尾部日志。

默认值: False
--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

容器组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az container restart

重启容器组中的所有容器。

重启容器组中的所有容器。 如果容器映像有更新,则会下载新映像。

az container restart --name
                     --resource-group
                     [--no-wait]

必需参数

--name -n

容器组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

可选参数

--no-wait

不等待长时间运行的操作完成。

默认值: False
全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az container show

获取容器组的详细信息。

az container show [--ids]
                  [--name]
                  [--resource-group]
                  [--subscription]

示例

获取容器组的详细信息。 (自动生成)

az container show --name MyContainerGroup --resource-group MyResourceGroup

可选参数

--ids

一个或多个资源 ID(以空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

容器组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az container start

启动容器组中的所有容器。

启动容器组中的所有容器。 将分配计算资源,并启动计费。

az container start --name
                   --resource-group
                   [--no-wait]

必需参数

--name -n

容器组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

可选参数

--no-wait

不等待长时间运行的操作完成。

默认值: False
全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az container stop

停止容器组中的所有容器。

停止容器组中的所有容器。 计算资源将解除分配且计费将停止。

az container stop --name
                  --resource-group

必需参数

--name -n

容器组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。