When we are using Google Cloud, we likely need to create multiple virtual machine (VM) instances of the same or similar environments. Google Cloud only provides some basic operating system images for you to start. However, the environments could be complicated. This means that you would have to configure the environment for all the instances, which is very tedious. A good way to deal with this is to use a custom image which has already configured the environment as the base operating system for new VM instances. In this blog post, we will learn how to create such custom images.
There are many ways of creating such custom images for Google Cloud. The official protocol could be found on Google Cloud. But I will only talk about the way which I feel the most comfortable. In this protocol, I am going to create a custom image that has NVIDIA-Docker installed. With NVIDIA-Docker, I can do almost everything related to deep learning on the VM instances using the custom image.
We first create a VM instance and configure this VM instance to the environment we want. Then we shut down the VM instance, and create a custom image based on the disk of the VM instance resides.
Create VM Instance
We use Ubuntu 18.04 LTS as our base operating system. We added more CPUs to make our installation of the new components faster. 10GB boot disk should be sufficient for our installation of NVIDIA-Docker and all of its dependencies. Make sure the boot disk is not too large as larger boot disk will make the building of our custom image slower and more costly in our method. You can always allocate more disk space to the VM instance once you have created the custom image.
Because installing NVIDIA-Docker requires GPU, don’t forget to request GPU when we create the VM instance.
Configure VM Instance
Once the VM instance was created, SSH to the VM instance. To install NVIDIA-Docker, we need NVIDIA driver, CUDA, and Docker. We use the NVIDIA-Docker bash script from Automated Environment Configurations to automate our installation.
Create Custom Image
In this method, we create a custom image from the disk that turned off VM instance was attached to. We turned off the VM instance to prevent the VM instance making changes to the disk while we are creating the custom image.
Once created, a new image called “nvidia-docker” will be listed under “Images”. You can then use this image as the base image for your new VM instances. The NVIDIA-docker has already been installed there.
All of these steps could be done in the terminal using the Google Cloud SDK to achieve further automation. But I am not going to talk about it here.