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:

None

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:

None

Step 2:

None

Step 3:

None
None
Pick a name for the instance and the type of GPU (NVIDIA V100, n1-standard-8 CPU here)

Step 4:

None
None
Pick a boot disk. For this example I picked Ubuntu 20.04 LTS with 100 GB disk space.

Step 5:

None
Create the instance

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:

None
None
None
Create machine image

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

None

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

Fixing IP Address

None
None
None
Reserve an IP address for the created instance

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

None

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 anuj

These 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).

None
None
A successful SSH

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 $USER

Setting 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.