Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcloud can only create instances using private image

I have a private image called 'test-1' and I can use it to create an instance

$ gcloud compute instances create demo --image test-1

However I cannot use a public image:

$ 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.

Nor a public image family:

$ 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

What am I doing wrong here?

like image 340
szabgab Avatar asked Feb 11 '19 10:02

szabgab


People also ask

What is a custom image in gcp?

By default, all Google Cloud projects have access to these images and can use them to create instances. Custom images are available only to your Cloud project. You can create a custom image from boot disks and other images. Then, use the custom image to create an instance.

What must you do before you create an instance with a GPU GCP?

Before you create an instance with a GPU, select which boot disk image you want to use for the instance, and ensure that the appropriate GPU driver is installed. To create an instance with one or more GPUs using the Google Cloud Platform Console, Go to the VM instances page.


1 Answers

I've noticed that in the generated error message, that you are generating the location of the image as if it is located in your project, which I understand it is named szabgab-149:

The resource 'projects/szabgab-149/global/images/family/ubuntu-1804-lts'

The thing is that public images are located in its own projects, see the output of the command gcloud compute images list.

For example, the ubuntu-1804-bionic-v20190204 is under the project ubuntu-os-cloud and the image family ubuntu-1804-lts.

To solve this, you can simply add the --image-project flag, from the information of the previous gcloud command, you execute this command, to use this specific image:

gcloud compute instances create demo \
--image ubuntu-1804-bionic-v20190204 \
--image-project ubuntu-os-cloud

Or this one, to use the default image under the project ubuntu-os-cloud and family ubuntu-1804-lts:

gcloud compute instances create demo \
--image-family ubuntu-1804-lts \
--image-project ubuntu-os-cloud
like image 78
Joan Grau Noël Avatar answered Oct 24 '22 16:10

Joan Grau Noël