Macindows
Macindows

Reputation: 209

How to create a gcp instance from a custom image?

In AWS I will create an AMI, copy to other regions and make them all public. My customers can then choose from Community AMIs.

I have been trying to replicate this workflow in GCP and I found that GCP does not have an option of community images. And you cannot make it 'public' either. But you can use gcloud compute images export command to export an image to an external file and upload it to a bucket.

But how to use this to create an instance? I checked console to 'create VM Instance' but it does not have an option to upload or choose from drive. Only public and custom images already in your account.

Upvotes: 2

Views: 2704

Answers (1)

Gautam Savaliya
Gautam Savaliya

Reputation: 1437

To share custom image publicly.

  1. Make custom image public using below command

    gcloud compute images add-iam-policy-binding [image-name] \
        --member='allAuthenticatedUsers' \
        --role='roles/compute.imageUser'
    
  2. Get public URL of custom image

    gcloud compute images list --uri | grep [image-name]
    

    It will be in https://www.googleapis.com/compute/v1/projects/[project-name]/global/images/[image-name] format

  3. Create VM using public image URL

    gcloud beta compute instances create instance-1 --zone=us-central1-a \
    --machine-type=n1-standard-1 --subnet=default \
    --image=https://www.googleapis.com/compute/v1/projects/[project-name]/global/images/[image-name] \
    --boot-disk-size=10GB --boot-disk-device-name=instance-1 
    

For details, gcp manage images here

Upvotes: 1

Related Questions