You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用PowerShell的Import-AzContainerRegistryImage导入带标签的ACR镜像

使用PowerShell导入ACR镜像替代Azure CLI命令

前提准备

首先确保已安装并导入Az.ContainerRegistry模块,若未安装可执行:

Install-Module -Name Az.ContainerRegistry -Force -AllowClobber
Import-Module Az.ContainerRegistry

同时需先登录Azure账号:

Connect-AzAccount

命令参数对应与转换

原Azure CLI命令:

az acr import --name $TARGET_REG --source $SOURCE_REG.azurecr.io/$repo":"$tag

转换为PowerShell的Import-AzContainerRegistryImage命令时,参数对应关系如下:

  • --name $TARGET_REG → -RegistryName $TARGET_REG(目标ACR名称)
  • --source 参数拆分为两个PowerShell参数:
    • -SourceRegistryUri:源ACR的完整URI,即$SOURCE_REG.azurecr.io
    • -SourceImage:需包含仓库名+标签,格式为$repo:$tag(原CLI里的引号可直接去掉)

完整PowerShell命令示例

# 定义变量
$TARGET_REG = "你的目标ACR名称"
$RG_NAME = "目标ACR所在资源组名称"
$SOURCE_REG = "源ACR名称"
$repo = "镜像仓库名"
$tag = "镜像标签"

# 执行导入
Import-AzContainerRegistryImage -RegistryName $TARGET_REG `
                                -ResourceGroupName $RG_NAME `
                                -SourceRegistryUri "$SOURCE_REG.azurecr.io" `
                                -SourceImage "$repo:$tag"

注意事项

  • 若源ACR是私有注册表,且当前登录账号无访问权限,需添加-SourceRegistryCredential参数传入源ACR的访问凭据:
    $sourceCred = Get-Credential -Message "输入源ACR的用户名和密码"
    Import-AzContainerRegistryImage -RegistryName $TARGET_REG `
                                    -ResourceGroupName $RG_NAME `
                                    -SourceRegistryUri "$SOURCE_REG.azurecr.io" `
                                    -SourceImage "$repo:$tag" `
                                    -SourceRegistryCredential $sourceCred
    
  • 确保目标ACR和源ACR的区域配置支持跨区域导入,避免因网络或权限限制导致失败。

内容的提问来源于stack exchange,提问作者Shilpa-V

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 07:45:51