Delete a custom image Stay organized with collections Save and categorize content based on your preferences.
You can only delete custom images that you, or someone who has access to theproject, have added.
Warning: Deleting a custom image is irreversible. You can't recover a deletedcustom image.If you want to retain a backup of the image,export the custom image toCloud Storage before deleting it.
Before you begin
- Read theImages document.
- If you haven't already, set upauthentication. Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.- Set a default region and zone.
Python
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.
Delete a custom image
Use one of the following methods to delete the image.
Console
In the Google Cloud console, go to theImages page.
Check the box to the left of the image you want to delete.
ClickDelete at the top of the page. Your image is deleted.
gcloud
Use thegcloud compute images delete commandto delete an image:
gcloud compute images deleteIMAGE_NAME
ReplaceIMAGE_NAME with the name of the image todelete.
Go
import("context""fmt""io"compute"cloud.google.com/go/compute/apiv1"computepb"cloud.google.com/go/compute/apiv1/computepb")// Deletes the specified disk imagefuncdeleteDiskImage(wio.Writer,projectID,imageNamestring,)error{// projectID := "your_project_id"// imageName := "your_image"ctx:=context.Background()imagesClient,err:=compute.NewImagesRESTClient(ctx)iferr!=nil{returnfmt.Errorf("NewImagesRESTClient: %w",err)}deferimagesClient.Close()req:=computepb.DeleteImageRequest{Image:imageName,Project:projectID,}op,err:=imagesClient.Delete(ctx,&req)iferr=op.Wait(ctx);err!=nil{returnfmt.Errorf("unable to wait for the operation: %w",err)}fmt.Fprintf(w,"Disk image %s deleted\n",imageName)returnnil}Java
importcom.google.cloud.compute.v1.ImagesClient;importcom.google.cloud.compute.v1.Operation;importjava.io.IOException;importjava.util.concurrent.ExecutionException;importjava.util.concurrent.TimeUnit;importjava.util.concurrent.TimeoutException;publicclassDeleteImage{publicstaticvoidmain(String[]args)throwsIOException,ExecutionException,InterruptedException,TimeoutException{// TODO(developer): Replace these variables before running the sample.// Project ID or project number of the Cloud project you use.Stringproject="your-project-id";// Name of the image you want to delete.StringimageName="your-image-name";deleteImage(project,imageName);}// Deletes a disk image.publicstaticvoiddeleteImage(Stringproject,StringimageName)throwsIOException,ExecutionException,InterruptedException,TimeoutException{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests. After completing all of your requests, call// the `imagesClient.close()` method on the client to safely// clean up any remaining background resources.try(ImagesClientimagesClient=ImagesClient.create()){Operationresponse=imagesClient.deleteAsync(project,imageName).get(3,TimeUnit.MINUTES);if(response.hasError()){System.out.println("Image deletion failed ! ! "+response);return;}System.out.printf("Operation Status for Image Name %s: %s ",imageName,response.getStatus());}}}Python
from__future__importannotationsimportsysfromtypingimportAnyfromgoogle.api_core.extended_operationimportExtendedOperationfromgoogle.cloudimportcompute_v1defwait_for_extended_operation(operation:ExtendedOperation,verbose_name:str="operation",timeout:int=300)->Any:""" Waits for the extended (long-running) operation to complete. If the operation is successful, it will return its result. If the operation ends with an error, an exception will be raised. If there were any warnings during the execution of the operation they will be printed to sys.stderr. Args: operation: a long-running operation you want to wait on. verbose_name: (optional) a more verbose name of the operation, used only during error and warning reporting. timeout: how long (in seconds) to wait for operation to finish. If None, wait indefinitely. Returns: Whatever the operation.result() returns. Raises: This method will raise the exception received from `operation.exception()` or RuntimeError if there is no exception set, but there is an `error_code` set for the `operation`. In case of an operation taking longer than `timeout` seconds to complete, a `concurrent.futures.TimeoutError` will be raised. """result=operation.result(timeout=timeout)ifoperation.error_code:print(f"Error during{verbose_name}: [Code:{operation.error_code}]:{operation.error_message}",file=sys.stderr,flush=True,)print(f"Operation ID:{operation.name}",file=sys.stderr,flush=True)raiseoperation.exception()orRuntimeError(operation.error_message)ifoperation.warnings:print(f"Warnings during{verbose_name}:\n",file=sys.stderr,flush=True)forwarninginoperation.warnings:print(f" -{warning.code}:{warning.message}",file=sys.stderr,flush=True)returnresultdefdelete_image(project_id:str,image_name:str)->None:""" Deletes a disk image. Args: project_id: project ID or project number of the Cloud project you use. image_name: name of the image you want to delete. """image_client=compute_v1.ImagesClient()operation=image_client.delete(project=project_id,image=image_name)wait_for_extended_operation(operation,"image deletion")REST
Make aPOST request to theimages().delete method.Specify the name of the image you want to delete.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/RESOURCE_ID
Replace the following:
PROJECT_ID: the project to which the imagebelongs.RESOURCE_ID: the name of the image that you wantto delete.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.