I wonder if someone can help.

I have some running instances. I'd like to get the image name of an instance boot disk (e.g., debian-10-buster-v20200618). It shows in the GCP console but neither of these commands fetch it:

gcloud compute instances list
gcloud compute instances list --format=json

Is there a way for GCloud to access this value? Could something (JS?) go directly to an API? Perhaps accessing the image family would be more useful but that probably needs to be derived from the image name. Could be that I'm missing something obvious :/

Any thoughts or suggestions gratefully received!


Solution Create an instance

gcloud compute instances create instance-1 --zone=europe-west1-b

Determine the image on which it was based

gcloud compute disks describe instance-1 --zone=europe-west1-b --format=json |
jq -r .sourceImage

(I've used JQ to filter down the response; W_B -- many thanks BTW -- uses Awk)


You can list disks with [gcloud compute disks list][1].

The disk name is usually same as the instance name.

The name you provided (debian-10-buster-v20200618) looks more like an image name of the disk. You can use gcloud compute images list in the same way as disks list.

If you want just the first column displayed and sorted by nanme then you can do gcloud compute disks list --sort-by=NAME | awk '{print $1}'.

This is just an example of what you can do - if you specify your desired output then I can edit my answer.

Here's how to use AWK to process any text output and make it more suited for your needs.

If you specify what's you desired output of this command I will edit the question and post exact command.

If the sorting capabilities of the gcloud arent enough you can use built in sort command.

To get a source image name which VM's disk was created from use gcloud compute disks describe yourinstancename --zone=myzone | grep image.

The result will look simillar to this: https://www.googleapis.com/compute/v1/projects/windows-cloud/global/images/windows-server-2012-r2-dc-v20200609

You can further use AWK to "tidy up" the results and get just the image name (for scripting etc).

| improve this answer | |
  • Thanks for the response. I did not explain myself properly. If you look at a VM details' page, in the boot disk section: the first column is Name, which, as you point out, is usually the same as the instance name -- it is the value of the second column Image, which displays the name of the image, that I'd like to retrieve. gcloud compute images list does contain that value but it does not tie it to the instances that are based on it. That is, with an instance's name, say instance-1, I'd like to retrieve the image from which the boot disk of instance-1 was built. – Rik Jul 10 at 17:12
  • 1
    Thanks for explanation - I've edited my answer to include image name. – Wojtek_B Jul 13 at 7:39
  • That's excellent -- just what I need -- thank you! Just FTR: gcloud compute instances create instance-1 --zone=europe-west1-b; gcloud compute disks describe instance-1 --zone=europe-west1-b --format=json | jq -r .sourceImage – Rik Aug 21 at 15:31
  • Thanks for the confirmation - if my answer helped you I would appreciate accepting it :) – Wojtek_B Aug 23 at 19:28
  • sorry, thought I had; done now and thanks again! – Rik Sep 2 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.