问题
I have a VM which is up and running and I have few applications in the VM. So I want to have an image of this VM so that I can create new instances with all the installed packages. I have option called clone, but instead cloning a VM I wanted to have it as an Image and create VM whenever I want.
回答1:
It's described here: https://cloud.google.com/compute/docs/creating-custom-image
Basically what it boils down to:
- Set the auto-delete state of the root persistent disk to false so that it is not automatically deleted when you delete the instance.
- Delete the instance.
gcloud compute images create example-image --source-disk example-disk --source-disk-zone ZONE
回答2:
https://github.com/khushbuparakh/gcp/blob/master/instance.py
You can use this. It creates a bucket. Upload your private file to the bucket. Create an image using that file and spin up an instance. Make sure the file you are uploading to bucket is in tar.gz compressed format with a disk.raw file in it.
来源:https://stackoverflow.com/questions/36701516/google-cloud-create-image-from-instance