6.10. 将 GCE 镜像复制到项目组中
您可以使用 GCE 镜像创建虚拟机(VM)实例。
先决条件
- 您创建的镜像的通用唯一标识符(UUID)。
- 访问 Image-builder 服务 API 端点。
- 从浏览器访问 Google Cloud Shell。
流程
- 在 Images 仪表板中复制您创建的镜像的 UUID 镜像。
- 访问 /composes/{composeId} API 端点。
- 点 composeId 字符串路径。 激活
-
在 API 端点的
composes/{composeId}
字段中输入 UUID。 单击 Response body 中生成一个响应,例如:
。API 端点在{ "image_status": { "status": "success", "upload_status": { "options": { "image_name": "composer-api-03f0e19c-0050-4c8a-a69e-88790219b086", "project_id": "red-hat-image-builder" }, "status": "success", "type": "gcp" } } }
从 Response body 字段中,复制 image_name 和 project_id,以从 Google Cloud Platform 环境访问镜像。从 Response body :
"image_name": "composer-api-03f0e19c-0050-4c8a-a69e-88790219b086", "project_id": "red-hat-image-builder"
- 从浏览器访问 Google Cloud Shell。
将 Google Cloud Platform Project ID 设置为默认的 GCP 项目。您可以通过访问 Google Cloud Platform 仪表盘 来查找项目的产品 ID。
$ gcloud config set project PROJECT_ID
- 在 Authorize Cloud Shell 窗口提示中,单击 以允许这个和将来需要您凭证的调用。
使用 gcloud 命令将镜像复制到项目中:
$ gcloud compute images create MY_IMAGE_NAME \ --source-image-project red-hat-image-builder \ --source-image IMAGE_NAME
其中:
- MY_IMAGE_NAME 是您提供给实例的名称;
- red-hat-image-builder 是 Response body 生成的 project_id ;
- IMAGE_NAME 是 Response body 生成的 image_name ;
验证
确认镜像是否已成功复制到项目中:
- 通过访问 Compute Engine / Images 部分使用 Google Cloud Platform UI。
通过在 Google Cloud Shell 中运行命令使用
gcloud
工具:$ gcloud compute images list --no-standard-images