使用 Azure CLI 在 Azure 市场中查找 Linux VM 映像Find Linux VM images in the Azure Marketplace with the Azure CLI

本主题介绍如何使用 Azure CLI 在 Azure 市场中查找 VM 映像。This topic describes how to use the Azure CLI to find VM images in the Azure Marketplace. 使用 CLI、资源管理器模板或其他工具以编程方式创建 VM 时,使用此信息指定市场映像。Use this information to specify a Marketplace image when you create a VM programmatically with the CLI, Resource Manager templates, or other tools.

还可以使用 Azure 市场店面、Azure 门户Azure PowerShell 浏览可用的映像和产品/服务。Also browse available images and offers using the Azure Marketplace storefront, the Azure portal, or Azure PowerShell.

请确保已安装最新版的 Azure CLI 且已登录到 Azure 帐户 (az login)。Make sure that you installed the latest Azure CLI and are logged in to an Azure account (az login).

术语Terminology

Azure 中的市场映像具有以下属性:A Marketplace image in Azure has the following attributes:

  • 发布者:创建映像的组织。Publisher: The organization that created the image. 示例:Canonical、MicrosoftWindowsServerExamples: Canonical, MicrosoftWindowsServer
  • 产品/服务:发布者创建的一组相关映像的名称。Offer: The name of a group of related images created by a publisher. 示例:UbuntuServer、WindowsServerExamples: UbuntuServer, WindowsServer
  • SKU:产品/服务的实例,例如分发版的主要版本。SKU: An instance of an offer, such as a major release of a distribution. 示例:18.04-LTS、2019-DatacenterExamples: 18.04-LTS, 2019-Datacenter
  • 版本:映像 SKU 的版本号。Version: The version number of an image SKU.

若要在以编程方式部署 VM 时标识市场映像,请以参数的形式单独提供这些值。To identify a Marketplace image when you deploy a VM programmatically, supply these values individually as parameters. 有些工具接受映像 URN ,它将这些值合并,值之间用冒号 (:) 字符隔开:发布者 :产品/服务 :Sku :版本 。Some tools accept an image URN, which combines these values, separated by the colon (:) character: Publisher:Offer:Sku:Version. 在 URN 中,可将版本号替换为“latest”,这会选择最新的映像版本。In a URN, you can replace the version number with "latest", which selects the latest version of the image.

如果映像发布者提供附加许可条款和购买条款,则必须接受这些条款并启用编程部署。If the image publisher provides additional license and purchase terms, then you must accept those terms and enable programmatic deployment. 以编程方式部署 VM 时,还需要提供“购买计划” 参数。You'll also need to supply purchase plan parameters when deploying a VM programmatically. 请参阅部署具有市场条款的映像See Deploy an image with Marketplace terms.

备注

在 Azure China 中使用 Azure CLI 2.0 之前,请首先运行 az cloud set -n AzureChinaCloud 更改云环境。Before you can use Azure CLI 2.0 in Azure China, please run az cloud set -n AzureChinaCloud first to change the cloud environment. 如果要切换回全局 Azure,请再次运行 az cloud set -n AzureCloudIf you want to switch back to Global Azure, run az cloud set -n AzureCloud again.

运行 az vm image list 命令,无需选择 --all 选项即可在 Azure 市场中查看常用 VM 映像的列表。Run the az vm image list command, without the --all option, to see a list of popular VM images in the Azure Marketplace. 例如,运行以下命令以表格形式显示缓存的常用映像列表:For example, run the following command to display a cached list of popular images in table format:

az vm image list --output table

输出包括映像 URN(Urn 列中的值) 。The output includes the image URN (the value in the Urn column). 使用其中一个常用市场映像创建 VM 时,可选择指定 UrnAlias(一种简短格式,如 UbuntuLTS)。When creating a VM with one of these popular Marketplace images, you can alternatively specify the UrnAlias, a shortened form such as UbuntuLTS.

You are viewing an offline list of images, use --all to retrieve an up-to-date list
Offer          Publisher               Sku                 Urn                                                             UrnAlias             Version
-------------  ----------------------  ------------------  --------------------------------------------------------------  -------------------  ---------
CentOS         OpenLogic               7.5                 OpenLogic:CentOS:7.5:latest                                     CentOS               latest
CoreOS         CoreOS                  Stable              CoreOS:CoreOS:Stable:latest                                     CoreOS               latest
Debian         credativ                8                   credativ:Debian:8:latest                                        Debian               latest
openSUSE-Leap  SUSE                    42.3                SUSE:openSUSE-Leap:42.3:latest                                  openSUSE-Leap        latest
RHEL           RedHat                  7-RAW               RedHat:RHEL:7-RAW:latest                                        RHEL                 latest
SLES           SUSE                    12-SP2              SUSE:SLES:12-SP2:latest                                         SLES                 latest
UbuntuServer   Canonical               16.04-LTS           Canonical:UbuntuServer:16.04-LTS:latest                         UbuntuLTS            latest
...

查找特定映像Find specific images

若要在市场中查找特定 VM 映像,请结合使用 az vm image list 命令和 --all 选项。To find a specific VM image in the Marketplace, use the az vm image list command with the --all option. 此版本命令完成需要一些时间,且会返回冗长输出,因此通常可按 --publisher 或其他参数筛选列表。This version of the command takes some time to complete and can return lengthy output, so you usually filter the list by --publisher or another parameter.

例如,以下命令显示所有 Debian 产品/服务(请记住,不使用 --all 开关时,只搜索常见映像的本地缓存):For example, the following command displays all Debian offers (remember that without the --all switch, it only searches the local cache of common images):

az vm image list --offer Debian --all --output table 

部分输出:Partial output:

Offer              Publisher    Sku                  Urn                                                    Version
-----------------  -----------  -------------------  -----------------------------------------------------  --------------
Debian             credativ     7                    credativ:Debian:7:7.0.201602010                        7.0.201602010
Debian             credativ     7                    credativ:Debian:7:7.0.201603020                        7.0.201603020
Debian             credativ     7                    credativ:Debian:7:7.0.201604050                        7.0.201604050
Debian             credativ     7                    credativ:Debian:7:7.0.201604200                        7.0.201604200
Debian             credativ     7                    credativ:Debian:7:7.0.201606280                        7.0.201606280
Debian             credativ     7                    credativ:Debian:7:7.0.201609120                        7.0.201609120
Debian             credativ     7                    credativ:Debian:7:7.0.201611020                        7.0.201611020
Debian             credativ     7                    credativ:Debian:7:7.0.201701180                        7.0.201701180
Debian             credativ     8                    credativ:Debian:8:8.0.201602010                        8.0.201602010
Debian             credativ     8                    credativ:Debian:8:8.0.201603020                        8.0.201603020
Debian             credativ     8                    credativ:Debian:8:8.0.201604050                        8.0.201604050
Debian             credativ     8                    credativ:Debian:8:8.0.201604200                        8.0.201604200
Debian             credativ     8                    credativ:Debian:8:8.0.201606280                        8.0.201606280
Debian             credativ     8                    credativ:Debian:8:8.0.201609120                        8.0.201609120
Debian             credativ     8                    credativ:Debian:8:8.0.201611020                        8.0.201611020
Debian             credativ     8                    credativ:Debian:8:8.0.201701180                        8.0.201701180
Debian             credativ     8                    credativ:Debian:8:8.0.201703150                        8.0.201703150
Debian             credativ     8                    credativ:Debian:8:8.0.201704110                        8.0.201704110
Debian             credativ     8                    credativ:Debian:8:8.0.201704180                        8.0.201704180
Debian             credativ     8                    credativ:Debian:8:8.0.201706190                        8.0.201706190
Debian             credativ     8                    credativ:Debian:8:8.0.201706210                        8.0.201706210
Debian             credativ     8                    credativ:Debian:8:8.0.201708040                        8.0.201708040
Debian             credativ     8                    credativ:Debian:8:8.0.201710090                        8.0.201710090
Debian             credativ     8                    credativ:Debian:8:8.0.201712040                        8.0.201712040
Debian             credativ     8                    credativ:Debian:8:8.0.201801170                        8.0.201801170
Debian             credativ     8                    credativ:Debian:8:8.0.201803130                        8.0.201803130
Debian             credativ     8                    credativ:Debian:8:8.0.201803260                        8.0.201803260
Debian             credativ     8                    credativ:Debian:8:8.0.201804020                        8.0.201804020
Debian             credativ     8                    credativ:Debian:8:8.0.201804150                        8.0.201804150
Debian             credativ     8                    credativ:Debian:8:8.0.201805160                        8.0.201805160
Debian             credativ     8                    credativ:Debian:8:8.0.201807160                        8.0.201807160
Debian             credativ     8                    credativ:Debian:8:8.0.201901221                        8.0.201901221
...

通过 --location--publisher--sku 选项应用类似的筛选器。Apply similar filters with the --location, --publisher, and --sku options. 可以在筛选器上执行部分匹配,如搜索 --offer Deb 以查找所有 Debian 映像。You can perform partial matches on a filter, such as searching for --offer Deb to find all Debian images.

如果没有使用 --location 选项指定一个特定位置,则将返回默认位置的值。If you don't specify a particular location with the --location option, the values for the default location are returned. (通过运行 az configure --defaults location=<location> 设置不同默认位置。)(Set a different default location by running az configure --defaults location=<location>.)

例如,以下命令列出了“中国北部”位置中的所有 Debian 8 SKU:For example, the following command lists all Debian 8 SKUs in the China North location:

az vm image list --location chinanorth --offer Deb --publisher credativ --sku 8 --all --output table

部分输出:Partial output:

Offer    Publisher    Sku                Urn                                              Version
-------  -----------  -----------------  -----------------------------------------------  -------------
Debian   credativ     8                  credativ:Debian:8:8.0.201602010                  8.0.201602010
Debian   credativ     8                  credativ:Debian:8:8.0.201603020                  8.0.201603020
Debian   credativ     8                  credativ:Debian:8:8.0.201604050                  8.0.201604050
Debian   credativ     8                  credativ:Debian:8:8.0.201604200                  8.0.201604200
Debian   credativ     8                  credativ:Debian:8:8.0.201606280                  8.0.201606280
Debian   credativ     8                  credativ:Debian:8:8.0.201609120                  8.0.201609120
Debian   credativ     8                  credativ:Debian:8:8.0.201611020                  8.0.201611020
Debian   credativ     8                  credativ:Debian:8:8.0.201701180                  8.0.201701180
Debian   credativ     8                  credativ:Debian:8:8.0.201703150                  8.0.201703150
Debian   credativ     8                  credativ:Debian:8:8.0.201704110                  8.0.201704110
Debian   credativ     8                  credativ:Debian:8:8.0.201704180                  8.0.201704180
Debian   credativ     8                  credativ:Debian:8:8.0.201706190                  8.0.201706190
Debian   credativ     8                  credativ:Debian:8:8.0.201706210                  8.0.201706210
Debian   credativ     8                  credativ:Debian:8:8.0.201708040                  8.0.201708040
Debian   credativ     8                  credativ:Debian:8:8.0.201710090                  8.0.201710090
Debian   credativ     8                  credativ:Debian:8:8.0.201712040                  8.0.201712040
Debian   credativ     8                  credativ:Debian:8:8.0.201801170                  8.0.201801170
Debian   credativ     8                  credativ:Debian:8:8.0.201803130                  8.0.201803130
Debian   credativ     8                  credativ:Debian:8:8.0.201803260                  8.0.201803260
Debian   credativ     8                  credativ:Debian:8:8.0.201804020                  8.0.201804020
Debian   credativ     8                  credativ:Debian:8:8.0.201804150                  8.0.201804150
Debian   credativ     8                  credativ:Debian:8:8.0.201805160                  8.0.201805160
Debian   credativ     8                  credativ:Debian:8:8.0.201807160                  8.0.201807160
Debian   credativ     8                  credativ:Debian:8:8.0.201901221                  8.0.201901221
...

在某个位置查找映像的另一种方法是,运行序列中的 az vm image list-publishersaz vm image list-offersaz vm image list-skus 命令。Another way to find an image in a location is to run the az vm image list-publishers, az vm image list-offers, and az vm image list-skus commands in sequence. 可以使用这些命令确定以下值:With these commands, you determine these values:

  1. 列出映像发布者。List the image publishers.
  2. 对于给定的发布者,列出其产品。For a given publisher, list their offers.
  3. 对于给定的产品,列出其 SKU。For a given offer, list their SKUs.

然后,对于所选 SKU,可以选择要部署的版本。Then, for a selected SKU, you can choose a version to deploy.

例如,以下命令列出了中国北部位置的映像发布者:For example, the following command lists the image publishers in the China North location:

az vm image list-publishers --location chinanorth --output table

部分输出:Partial output:

Location    Name
----------  ----------------------------------------------------
chinanorth  A10Networks
chinanorth  AllMobilize
chinanorth  alteonva
chinanorth  Antshares
chinanorth  array_networks
chinanorth  AsiaInfo.DeepSecurity
chinanorth  AzureChinaMarketplace
chinanorth  baison
chinanorth  BespinGlobal
chinanorth  beyondsoft
chinanorth  bjjzhj
chinanorth  blacklake2
chinanorth  BlueStoneEcommerceSolution
chinanorth  bw-jx
chinanorth  C3CRM
chinanorth  Canonical
...

使用此信息可以从特定发布者找到产品/服务。Use this information to find offers from a specific publisher. 例如,对于位于中国北部位置的 Canonical 发布者,请通过运行 azure vm image list-offers 查找产品/服务。For example, for the Canonical publisher in the China North location, find offers by running azure vm image list-offers. 传递位置和发布者,如以下示例中所示:Pass the location and the publisher as in the following example:

az vm image list-offers --location chinanorth --publisher Canonical --output table

输出:Output:

Location    Name
----------  -------------------------
chinanorth      Ubuntu15.04Snappy
chinanorth      Ubuntu15.04SnappyDocker
chinanorth      UbunturollingSnappy
chinanorth      UbuntuServer
chinanorth      Ubuntu_Core

可以看到,在中国北部区域,Canonical 在 Azure 上发布了 UbuntuServer 产品。You see that in the China North region, Canonical publishes the UbuntuServer offer on Azure. 但是,有哪些 SKU 呢?But what SKUs? 要获取这些值,请运行 azure vm image list-skus,并对找到的位置、发布者和产品/服务进行设置:To get those values, run azure vm image list-skus and set the location, publisher, and offer that you discovered:

az vm image list-skus --location chinanorth --publisher Canonical --offer UbuntuServer --output table

输出:Output:

Location    Name
----------  -----------------
chinanorth      12.04.3-LTS
chinanorth      12.04.4-LTS
chinanorth      12.04.5-LTS
chinanorth      14.04.0-LTS
chinanorth      14.04.1-LTS
chinanorth      14.04.2-LTS
chinanorth      14.04.3-LTS
chinanorth      14.04.4-LTS
chinanorth      14.04.5-DAILY-LTS
chinanorth      14.04.5-LTS
chinanorth      16.04-DAILY-LTS
chinanorth      16.04-LTS
chinanorth      16.04.0-LTS
chinanorth      17.10
chinanorth      17.10-DAILY
chinanorth      18.04-DAILY-LTS
chinanorth      18.04-LTS
chinanorth      18.10-DAILY

最后,使用 az vm image list 命令查找所需的特定版本的 SKU,例如,18.04-LTS :Finally, use the az vm image list command to find a specific version of the SKU you want, for example, 18.04-LTS:

az vm image list --location chinanorth --publisher Canonical --offer UbuntuServer --sku 18.04-LTS --all --output table

部分输出:Partial output:

Offer         Publisher    Sku        Urn                                               Version
------------  -----------  ---------  ------------------------------------------------  ---------------
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201804262  18.04.201804262
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201805170  18.04.201805170
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201805220  18.04.201805220
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201806130  18.04.201806130
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201806170  18.04.201806170
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201807240  18.04.201807240
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201808060  18.04.201808060
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201808080  18.04.201808080
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201808140  18.04.201808140
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201808310  18.04.201808310
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201809110  18.04.201809110
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201810030  18.04.201810030
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201810240  18.04.201810240
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201810290  18.04.201810290
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201811010  18.04.201811010
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201812031  18.04.201812031
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201812040  18.04.201812040
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201812060  18.04.201812060
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201901140  18.04.201901140
UbuntuServer  Canonical    18.04-LTS  Canonical:UbuntuServer:18.04-LTS:18.04.201901220  18.04.201901220
...

现在,可通过记下 URN 值准确地选择想要使用的映像。Now you can choose precisely the image you want to use by taking note of the URN value. 通过 az vm create 命令创建 VM 时,可将此值与 --image 参数一起传递。Pass this value with the --image parameter when you create a VM with the az vm create command. 记住,可选择将 URN 中的版本号替换为“latest”。Remember that you can optionally replace the version number in the URN with "latest". 此版本始终是映像的最新版本。This version is always the latest version of the image.

如果使用资源管理器模板部署 VM,请在 imageReference 属性中单独设置映像参数。If you deploy a VM with a Resource Manager template, you set the image parameters individually in the imageReference properties.

部署具有市场条款的映像Deploy an image with Marketplace terms

Azure 市场中的某些 VM 映像具有附加许可条款和购买条款,你必须接受这些条款,然后才能以编程方式部署这些映像。Some VM images in the Azure Marketplace have additional license and purchase terms that you must accept before you can deploy them programmatically.

若要从此类映像部署 VM,需要同时接受映像的条款并启用编程部署。To deploy a VM from such an image, you'll need to both accept the image's terms and enable programmatic deployment. 只需对每个订阅执行一次此操作。You'll only need to do this once per subscription. 此后,每次以编程方式从映像部署 VM 时,还需要指定“购买计划” 参数。Afterward, each time you deploy a VM programmatically from the image you'll also need to specify purchase plan parameters.

以下部分介绍如何执行这些操作:The following sections show how to:

  • 了解市场映像是否具有附加许可条款Find out whether a Marketplace image has additional license terms
  • 以编程方式接受条款Accept the terms programmatically
  • 以编程方式部署 VM 时提供购买计划参数Provide purchase plan parameters when you deploy a VM programmatically

查看计划属性View plan properties

若要查看映像的购买计划信息,请运行 az vm image show 命令。To view an image's purchase plan information, run the az vm image show command. 如果输出中的 plan 属性不是 null,则映像有条款,在以编程方式部署前需要接受该条款。If the plan property in the output is not null, the image has terms you need to accept before programmatic deployment.

例如,Canonical Ubuntu Server 18.04 LTS 映像没有附加条款,因为 plan 信息为 nullFor example, the Canonical Ubuntu Server 18.04 LTS image doesn't have additional terms, because the plan information is null:

az vm image show --location chinanorth --urn Canonical:UbuntuServer:18.04-LTS:latest

输出:Output:

{
  "dataDiskImages": [],
  "id": "/Subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Providers/Microsoft.Compute/Locations/chinanorth/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/18.04-LTS/Versions/18.04.201901220",
  "location": "chinanorth",
  "name": "18.04.201901220",
  "osDiskImage": {
    "operatingSystem": "Linux"
  },
  "plan": null,
  "tags": null
}

后续步骤Next steps

若要使用映像信息快速创建虚拟机,请参阅使用 Azure CLI 创建和管理 Linux VMTo create a virtual machine quickly by using the image information, see Create and Manage Linux VMs with the Azure CLI.