以映像檔系列簡化映像檔版本的設定工作。新增映像檔到映像檔系列中,將它設定為系列中最新的映像檔版本。如果您決定必須將映像檔系列復原為前一個映像檔版本,請淘汰系列中最新的映像檔。
如要瞭解使用映像檔系列時的最佳做法,請參閱「映像檔系列最佳做法」。
您可以視需要選擇使用Google Cloud 主控台、具有 --storage-location
旗標的 gcloud compute images create
指令,或 images().insert
方法來指定映像檔的儲存位置。
事前準備
- 參閱「圖片」說明文件。
-
如果尚未設定,請先設定驗證機制。「驗證」是指驗證身分,以便存取 Google Cloud 服務和 API 的程序。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,以便對 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
前往 Google Cloud 控制台的「Create an image」(建立映像檔) 頁面。
指定映像檔的「Name」(名稱)。例如:
image-v1
。指定您要建立映像檔的「Source」(來源)。這可以是 Cloud Storage 中的永久磁碟、快照、其他映像檔或 disk.raw 檔案。
如要從連結到執行中 VM 的磁碟建立映像檔,請勾選「Keep instance running」,確認您要在 VM 執行時建立映像檔。您可以在建立映像檔前準備 VM。
在「Based on source disk location (default)」(根據來源磁碟位置 (預設值)) 下拉式選單中,指定要儲存圖片的位置。例如,指定
us
會將圖片儲存在us
多地區;指定us-central1
則會儲存在us-central1
地區。如果未選擇位置,Compute Engine 會將映像檔儲存在最靠近映像檔來源位置的多地區。為新圖片指定系列。例如,新增
my-image-family
來將圖片整理為映像檔系列的一部分。選用:指定其他圖片屬性:
- 說明:自訂圖片的說明。
- 標籤:標籤可用來將資源分組。
指定加密金鑰。您可以選擇 Google-owned and Google-managed encryption key、Cloud Key Management Service (Cloud KMS) 金鑰或客戶提供的加密金鑰 (CSEK)。如果未指定加密金鑰,系統會使用 Google-owned and Google-managed encryption key為圖片加密。
按一下 [建立] 以建立映像檔。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「驗證以使用 REST」。
在映像檔系列中設定映像檔版本
主控台
gcloud
gcloud compute images create image-v1 \ --source-disk disk-1 \ --source-disk-zone us-central1-f \ --family my-image-family
映像檔系列指向
image-v1
。新增第二個映像檔到系列:gcloud compute images create image-v2 \ --source-disk disk-2 \ --source-disk-zone us-central1-f \ --family my-image-family
REST
對
images().insert
方法提出POST
要求。在要求主體中指定映像檔系列。POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images { "name": "image-v2", "sourceDisk": "/zones/us-central1-f/disks/disk-2", "family":"my-image-family", }
映像檔系列指向
image-v2
,因為它是您新增至映像檔系列的最新映像檔。gcloud
您可以執行
gcloud compute images describe-from-family
指令,查看系列指向哪個映像檔。例如:
gcloud compute images describe-from-family my-image-family family: my-image-family id: '8904691942610171306' kind: compute#image name: image-v2 selfLink: https://compute.googleapis.com/compute/v1/projects/my-project/global/images/image-v2 sourceDisk: https://compute.googleapis.com/compute/v1/projects/my-project/zones/us-central1-f/disks/disk-v2 sourceDiskId: '1677449456001963379' sourceType: RAW status: READY
REST
對
images().getFromFamily
方法提出GET
要求。在要求主體中指定映像檔系列。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/family { "resourceId":"my-image-family", }
如果您決定復原映像檔系列,使它不再指向
image-v2
,請淘汰image-v2
,系列就會再次指向image-v1
。gcloud compute images deprecate image-v2 \ --state DEPRECATED \ --replacement image-v1
檢查並確認映像檔系列指向了
image-v1
。gcloud compute images describe-from-family my-image-family family: my-image-family id: '2741732787056801255' kind: compute#image name: image-v1 selfLink: https://compute.googleapis.com/compute/v1/projects/my-project/global/images/image-v1 sourceDisk: https://compute.googleapis.com/compute/v1/projects/my-project/zones/us-central1-f/disks/disk-v1 sourceDiskId: '1677449456001963379' sourceType: RAW status: READY
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-16 (世界標準時間)。
-