Setup Docker environment using NVIDIA’s GPGPU with WSL2 on Windows 11

This is a note on setting up a Docker environment using NVIDIA’s GPGPU with WSL2 on Windows 11.

1. About Hardware and Installed Software

I used a desktop computer ESPRIMO WD2/H2 with NVIDIA GeForce GTX 1650.

I started setting up the environment on Windows 11 with the NVIDIA GeForce GTX 1650 driver (NVIDIA Studio driver) and CUDA Toolkit 12.4 for Windows installed.

2. I booted Ubuntu 22.04 on WSL2 and followed the steps below to set up the environment.

2.1. I installed the NVIDIA Container Toolkit following the instructions in “Installing with Apt” on the following page from NVIDIA.

https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html

2.1.1. The configuration of the apt repository was updated with the following command.

fukagai@ESPRIMOWD2H2:~$ curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
  && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
    sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
    sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://nvidia.github.io/libnvidia-container/stable/deb/$(ARCH) /
#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://nvidia.github.io/libnvidia-container/experimental/deb/$(ARCH) /

2.1.2. The list of apt packages was updated with the following command.

fukagai@ESPRIMOWD2H2:~$ sudo apt-get update
Get:1 https://nvidia.github.io/libnvidia-container/stable/deb/amd64  InRelease [1477 B]
Get:2 https://nvidia.github.io/libnvidia-container/stable/deb/amd64  Packages [9176 B]
Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
...
Get:40 http://archive.ubuntu.com/ubuntu jammy-backports/multiverse amd64 c-n-f Metadata [116 B]
Fetched 31.1 MB in 10s (3012 kB/s)
Reading package lists... Done

2.1.3. NVIDIA Container Toolkit was installed with the following command.

fukagai@ESPRIMOWD2H2:~$ sudo apt-get install -y nvidia-container-toolkit
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libnvidia-container-tools libnvidia-container1 nvidia-container-toolkit-base
The following NEW packages will be installed:
  libnvidia-container-tools libnvidia-container1 nvidia-container-toolkit nvidia-container-toolkit-base
0 upgraded, 4 newly installed, 0 to remove and 100 not upgraded.
...
Setting up nvidia-container-toolkit (1.15.0-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.4) ...
/sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link

2.2. I installed Docker following the instructions on the following page.

https://docs.docker.com/engine/install/ubuntu/

2.2.1. The following commands were used to set up the Docker apt repository.

fukagai@ESPRIMOWD2H2:~$ sudo apt-get install ca-certificates curl
fukagai@ESPRIMOWD2H2:~$ sudo install -m 0755 -d /etc/apt/keyrings
fukagai@ESPRIMOWD2H2:~$ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
fukagai@ESPRIMOWD2H2:~$ sudo chmod a+r /etc/apt/keyrings/docker.asc
fukagai@ESPRIMOWD2H2:~$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
fukagai@ESPRIMOWD2H2:~$ sudo apt-get update
Get:1 https://download.docker.com/linux/ubuntu jammy InRelease [48.8 kB]
Hit:2 https://nvidia.github.io/libnvidia-container/stable/deb/amd64  InRelease
Get:3 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [31.5 kB]
Get:4 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Hit:5 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:6 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Hit:7 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Fetched 309 kB in 2s (140 kB/s)
Reading package lists... Done

2.2.2. The following command installed the Docker package.

fukagai@ESPRIMOWD2H2:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

2.2.3. The following command was used to check the operation of the installed Docker.

fukagai@ESPRIMOWD2H2:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:a26bff933ddc26d5cdf7faa98b4ae1e3ec20c4985e6f87ac0973052224d24302
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
...

2.3. I executed the following commands following the instructions in the “Configuring Docker” section of the following page from NVIDIA.

https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html

fukagai@ESPRIMOWD2H2:~$ sudo nvidia-ctk runtime configure --runtime=docker
INFO[0000] Config file does not exist; using empty config
INFO[0000] Wrote updated config to /etc/docker/daemon.json
INFO[0000] It is recommended that docker daemon be restarted.
fukagai@ESPRIMOWD2H2:~$ sudo systemctl restart docker

The above commands will enable Docker to use NVIDIA Container Runtime.
After executing the command, /etc/docker/daemon.json has the following content.

fukagai@ESPRIMOWD2H2:~$ cat /etc/docker/daemon.json
{
    "runtimes": {
        "nvidia": {
            "args": [],
            "path": "nvidia-container-runtime"
        }
    }
}

2.4. I executed the command described in “Running a Sample Workload with Docker” on the following page from NVIDIA.

https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/sample-workload.html

When the following command was executed, the following message was output to the console.

fukagai@ESPRIMOWD2H2:~$ sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
Sun May  5 05:12:27 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.76.01              Driver Version: 552.22         CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce GTX 1650        On  |   00000000:01:00.0 Off |                  N/A |
| 23%   42C    P8             N/A /   75W |     619MiB /   4096MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A        25      G   /Xwayland                                   N/A      |
+-----------------------------------------------------------------------------------------+

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA