Install gcloud CLI
Following the instructions at https://cloud.google.com/sdk/docs/install for Google Cloud CLI installation.
Setup a gcloud project
Once the gcloud is entergcloud projects create demoproject32, followed by gcloud config set project demoproject32 on the terminal to set up a new project configuration.
If everything goes without error, gcloud config configurations list, should give the following:

Setting up a GCP Instance
When doing it for the first time, login to your Google Cloud account and follow the steps below
Step 1:

Step 2:

Step 3:


Step 4:


Step 5:

Second time onwards, we do not need to setup an instance from scratch. One can save a machine image of existing instance and clone a new instance. Procedure for cloning is as follows:
Step 1:



Step 2: After Step 1 & 2 of precious section, begin the procedure for creating 'New VM instance from machine image'.

This also eliminates the need for setting up Docker and NVIDIA dependencies (discussed below)
Fixing IP Address



Ensure that the reserved external IP address is correctly assigned to the VM Instance

Setting up SSH connection
SSH Key configuration
Config Setting
Use fixed external IP address as HostName
% nano ~/.ssh/config
...
Host instance-1
HostName 34.69.84.97
User anujThese settings allow direct SSH from VS Code without gcloud command.
SSH Connection through VS code
In a new VS Code window, connect to the configured host (instance-1).


Install CUDA
Follow instructions for CUDA installation. It may take some time. With successful installation it is possible to use nvidia-smi
Install Docker & docker-compose
Follow instructions here. Give sudo access
sudo usermod -aG docker $USERSetting up NVIDIA Container Toolkit
NVIDIA Container Toolkit installation guide
After the installation, please restart the instance in case sudo docker run --rm --gpus all nvidia/cuda:11.1.1-devel-ubuntu20.04 nvidia-smi throws an error. Successful installation should result in
Building & Running a docker container
Build: sudo docker build -t demo-container -f Dockerfile .
Compose: sudo docker compose -f docker-compose.yml -p demo-container up -d
Run: sudo docker exec -it demo-container-demo-container-1 bash
With this you should be able to enter the container environment from the comfort of VS Code.
If you find this valuable and would like to support me as a writer, please consider following me or signing up for Medium membership.