- Run a container over VM with a pre-installed application image
- Run a container over VM with a custom Docker image from the public registry
Costs
The tutorial includes the following chargeable resources:Prerequisites
Create an SSH key pair for the virtual machine:-
Run the following command:
- Enter the file name where to store the key pair.
- (Optionally) Enter a passphrase.
Steps
Run a container over VM with a pre-installed application image
Create a single-GPU VM with Jupyter Notebook
-
In the web console, go to
Compute → Containers over VMs.
-
Click
Create container over VM.
- Specify the VM name.
- Select the Jupyter Notebook container image.
- Copy and save the token that appears. You will need this token later to access the JupyterLab web interface.
- In Computing resources, configure the VM with one GPU. For example, select NVIDIA® L40S PCIe with Intel Ice Lake and keep the predefined preset with eight CPUs.
- In Local storage, specify the disk size.
-
In Access, add new credentials or select existing ones.
To add new credentials:
-
Specify the username. Do not use the
rootoradminusernames. They are reserved for internal needs and cannot be used for SSH access. -
Copy the contents of the
.pubfile generated earlier and paste it into the Public key field. - Click Add credentials.
-
Specify the username. Do not use the
- Click Create container over VM.
Launch Jupyter Notebook
When the container over VM is running, connect to the application:- In Containers over VMs, open the page of the created VM.
- Click Go to Web UI at the top of the VM page.
- When prompted, paste the token into the authentication field and click Log in.
- In JupyterLab, create a new notebook.
-
Run the following code. It shows information about available GPUs:
Example output:
Benchmark a VM with one GPU
Run a simple benchmark to measure how long the GPU takes to multiply large matrices. This test multiplies two 30,000×30,000 tensors several times and measures the total execution time. Later in the tutorial, you will repeat the same benchmark on a VM with eight GPUs and compare the results. Run the following code:Replace the VM with an 8-GPU VM while preserving data
To scale from one GPU to eight GPUs and keep your notebooks:- Delete the current VM. When deleting the VM, select the option to keep the boot disk.
- Create a new container over VM as described in the Create a single-GPU VM with Jupyter Notebook section, but:
- In Computing resources, choose a configuration with eight GPUs
- Attach the existing disk that contains your data as an additional disk
Benchmark a VM with eight GPUs
Run the benchmark test again on the VM with eight GPUs to measure how the workload performs after scaling.- Go to Jupyter Notebook and open your existing notebook.
-
Replace the benchmark code with:
Example output:This demonstrates the performance improvement when scaling from one GPU to eight GPUs.
Run a container over VM with a custom Docker image
In the previous section, you deployed a container over VM by using a pre-installed application image with Jupyter Notebook. You can also deploy containers with custom Docker images from public registries. In this section, you will create a container over VM by using a Docker image from Docker Hub and access the application running inside the container. The TensorFlow Jupyter image is used as an example. This image includes both TensorFlow and Jupyter Notebook, so you can run TensorFlow workloads directly in a notebook environment.Create a container over VM with a custom Docker image
- In the web console, go to
Compute → Containers over VMs.
- Click
Create container over VM.
- Specify the VM name.
- Select Custom Image.
- In Docker Image, enter
tensorflow/tensorflow:nightly-gpu-jupyter. - In Docker run arguments, specify
--restart=always --gpus all --shm-size=16GB -p 8888:8888. These arguments enable GPU access, allocate shared memory and expose port 8888 for Jupyter Notebook. - In Computing resources, use at least one GPU.
- In Local storage, specify the disk size.
- In Access, select the previously created credentials.
- Click Create container over VM.
Connect to the VM
When the container over VM is running, connect to the application:- In the Containers over VMs section, open the page of the VM with the custom Docker image installed.
- In the Network section, copy the Public IPv4 address.
-
Connect to the VM by using SSH:
-
List the running containers and copy the name of the TensorFlow container:
-
Get the Jupyter token:
-
Open in browser
http://<public_IP_address>:8888/?token=<jupyter_token>. -
In JupyterLab, create a new notebook and run the following code to verify that TensorFlow works in the container:
Example output:This example performs large matrix multiplication by using TensorFlow and prints the execution time.
How to delete the created resources
The created Compute VMs and their boot disks are chargeable. If you do not need them, delete the resources created during this tutorial:- Go to
Compute → Containers over VMs.
- Open the VM page.
- Switch to Settings.
- Click Delete virtual machine.
- In the window that opens, select Delete the boot disk.
- Confirm the deletion.
- Repeat these steps for any other VMs created during this tutorial.