Common gcloud compute commands

This document lists some of the most commonly used gcloud compute commands.

Before you begin

Describing projects

Run the following command to query information about your Compute Engine project, such as project metadata, ssh keys, and quota metrics:

 gcloud compute project-info describe

For more information about describing your project, see the gcloud compute project-info describe reference documentation.

Working with VMs

The following examples show common tasks when working with virtual machine (VM) instances. For more information about virtual machine (VM) instances, see Virtual machine instances.

Creating VMs

Run the following command to create a VM:

gcloud compute instances create VM_NAME \
    [--image IMAGE | --image-family IMAGE_FAMILY] \
    --image-project IMAGE_PROJECT

Replace the following:

  • VM_NAME: the name of the new VM.
  • IMAGE or IMAGE_FAMILY: Specify one of the following:
    • IMAGE: required version of a public image. For example, --image debian-10-buster-v20200309.
    • IMAGE_FAMILY: an image family. This creates the VM from the most recent, non-deprecated OS image. For example, if you specify --image-family debian-10, Compute Engine creates a VM from the latest version of the OS image in the Debian 10 image family.
  • IMAGE_PROJECT: the project containing the image.

For more information about creating VMs, see Creating and starting a VM instance and the gcloud compute instances create reference documentation.

Listing VMs

Run the following command to display all VMs in a project:

gcloud compute instances list

For more information about listing VMs, see the gcloud compute instances list reference documentation.

Describing VMs

Run the following command to display all data associated with a VM:

gcloud compute instances describe VM_NAME

Replace VM_NAME with the name of the VM.

For more information about describing VMs, see the gcloud compute instances describe reference documentation.

Starting VMs

Run the following command to start a stopped VM:

gcloud compute instances start VM_NAME

Replace VM_NAME with the name of the VM.

For more information about starting VMs, see Starting and stopping an instance and the gcloud compute instances start reference documentation.

Stopping VMs

Run the following command to stop a VM:

gcloud compute instances stop VM_NAME

Replace VM_NAME with the name of the VM.

For more information about stopping VMs, see Starting and stopping an instance and the gcloud compute instances stop reference documentation.

Adding labels to VMs

Run the following command to add labels to VMs:

gcloud compute instances add-labels VM_NAME \
    --label=KEY=VALUE

Replace the following:

  • VM_NAME: the name of the VM.
  • KEY=VALUE: the key-value pair of the label.

For more information about labeling VMs, see Labeling resources and the gcloud compute instances add-labels reference documentation.