以映像檔系列簡化映像檔版本的設定工作。新增映像檔到映像檔系列中,將它設定為系列中最新的映像檔版本。如果您決定必須將映像檔系列復原為前一個映像檔版本,請淘汰系列中最新的映像檔。
如需使用映像檔系列的最佳做法,請參閱映像檔系列最佳做法。
您可以視需要選擇使用Trusted Cloud 主控台、具有 --storage-location
旗標的 gcloud compute images create
指令,或 images().insert
方法來指定映像檔的儲存位置。
事前準備
- 參閱映像檔文件。
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Trusted Cloud by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
- Set a default region and zone.
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
詳情請參閱 Trusted Cloud 驗證說明文件中的「Authenticate for using REST」。
在映像檔系列中設定映像檔版本
主控台
前往 Trusted Cloud 控制台的「Create an image」(建立映像檔) 頁面。
指定映像檔的「Name」(名稱)。例如:
image-v1
。指定您要建立映像檔的「Source」(來源)。這可以是永久磁碟、快照、另一個映像檔,或 Cloud Storage 中的 disk.raw 檔案。
如要從連結到執行中 VM 的磁碟建立映像檔,請勾選「讓執行個體繼續執行」,確認要在 VM 執行時建立映像檔。您可以先準備 VM,再建立映像檔。
在「Based on source disk location (default)」(根據來源磁碟位置 (預設值)) 下拉式清單中,指定儲存映像檔的位置。例如,指定
us
會將映像檔儲存在us
多地區;指定us-central1
則會儲存在us-central1
地區。如果未選擇位置,Compute Engine 會將映像檔儲存在最靠近映像檔來源位置的多地區。為新映像檔指定映像檔系列。例如,新增
my-image-family
,將映像檔整理為映像檔系列的成員。選用:指定其他圖片屬性:
- 說明:自訂圖片的說明。
- 標籤:用來將資源分組的標籤。
指定加密金鑰。您可以選擇 Google Cloud-powered encryption key、Cloud Key Management Service (Cloud KMS) 金鑰或客戶提供的加密 (CSEK) 金鑰。如未指定加密金鑰,系統會使用 Google Cloud-powered encryption key加密圖片。
按一下 [建立] 以建立映像檔。
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-08-08 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-08 (世界標準時間)。"],[[["Image families simplify image versioning by allowing you to group related images and designate the most recent version."],["Adding a new image to an existing image family automatically sets it as the newest version within that family."],["You can manage the storage location of an image during creation using the Google Cloud console, the `gcloud compute images create` command, or the `images().insert` method."],["Rolling back to a previous image version involves deprecating the most recent image, which then reverts the family's pointer to the prior version."],["The `gcloud compute images describe-from-family` command or the `images().getFromFamily` method allows you to confirm which image a specific image family currently references."]]],[]] -