gcloud 只能使用私有镜像创建实例

sza*_*gab 6 google-cloud-platform gcloud

我有一个名为“test-1”的私有镜像,我可以用它来创建一个实例

$ gcloud compute instances create demo --image test-1
Run Code Online (Sandbox Code Playgroud)

但是我不能使用公共图像:

$ gcloud compute instances create demo --image ubuntu-1804-bionic-v20190204 
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
 - Invalid value for field 'resource.disks[0].initializeParams.sourceImage': 'https://www.googleapis.com/compute/v1/projects/szabgab-149/global/images/ubuntu-1804-bionic-v20190204'. The referenced image resource cannot be found.
Run Code Online (Sandbox Code Playgroud)

也不是公共图像系列:

$ gcloud compute instances create demo --image-family ubuntu-1804-lts 
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
 - The resource 'projects/szabgab-149/global/images/family/ubuntu-1804-lts' was not found
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?

Joa*_*oël 10

我注意到在生成的错误消息中,您正在生成图像的位置,就好像它位于您的项目中一样,我知道它被命名为szabgab-149

资源“projects/ szabgab-149 /global/images/family/ubuntu-1804-lts”

事情是公共图像位于其自己的项目中,请参阅命令的输出gcloud compute images list

例如,ubuntu-1804-bionic-v20190204项目下的isubuntu-os-cloud和 image family ubuntu-1804-lts

要解决这个问题,您可以简单地添加--image-project标志,从上一个 gcloud 命令的信息中,您执行此命令,以使用此特定图像:

gcloud compute instances create demo \
--image ubuntu-1804-bionic-v20190204 \
--image-project ubuntu-os-cloud
Run Code Online (Sandbox Code Playgroud)

或者这个,使用项目ubuntu-os-cloud和家庭下的默认图像ubuntu-1804-lts

gcloud compute instances create demo \
--image-family ubuntu-1804-lts \
--image-project ubuntu-os-cloud
Run Code Online (Sandbox Code Playgroud)