Deep Docker on Arch

The NVIDIA Container Toolkit allows users to build and run GPU accelerated Docker containers. The toolkit includes a container runtime library and utilities to automatically configure containers to leverage NVIDIA GPUs.
Preparations
Make sure you have installed the NVIDIA driver and Docker engine for your Linux distribution. Note that you do not need to install the CUDA Toolkit on the host system.
sudo pacman -Syu
sudo pacman -S base-devel linux-headers git nano --needed
Verify what version of the nVidia driver you need:
lspci -k | grep -A 2 -E "(VGA|3D)"
00:02.0 VGA compatible controller: Intel Corporation HD Graphics 630 (rev 04)
DeviceName: Onboard IGD
Subsystem: Dell HD Graphics 630
--
01:00.0 VGA compatible controller: NVIDIA Corporation GP106M [GeForce GTX 1060 Mobile] (rev a1)
Subsystem: Dell GP106M [GeForce GTX 1060 Mobile]
Kernel driver in use: nouveau
Install a suitable version:
sudo pacman -S cuda cudnn nvidia nvidia-utils nvidia-settings opencl-nvidia xorg-server-devel
reboot
Verify that the installation worked:
sudo nvidia-smi
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.90.07 Driver Version: 550.90.07 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 1080 Ti Off | 00000000:01:00.0 Off | N/A |
| 33% 32C P8 9W / 250W | 170MiB / 11264MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
| 1 NVIDIA GeForce GTX 1080 Ti Off | 00000000:08:00.0 Off | N/A |
| 33% 30C P8 9W / 250W | 7MiB / 11264MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 914 G /usr/lib/Xorg 163MiB |
| 0 N/A N/A 1019 G xfwm4 3MiB |
| 1 N/A N/A 914 G /usr/lib/Xorg 4MiB |
+-----------------------------------------------------------------------------------------+
Installation in Arch Linux
Starting from Docker version 19.03, NVIDIA GPUs are natively supported as Docker devices. NVIDIA Container Toolkit is the recommended way of running containers that leverage NVIDIA GPUs.
Install the nvidia-container-toolkit package. Next, restart docker. You can now run containers that make use of NVIDIA GPUs using the --gpus option.
YAY
yay -Syu
yay -S nvidia-container-toolkit
And restart Docker:
sudo systemctl restart docker
Manually
wget https://aur.archlinux.org/cgit/aur.git/snapshot/nvidia-container-toolkit.tar.gz
tar -xf nvidia-container-toolkit.tar.gz && cd nvidia-container-toolkit/
makepkg
sudo pacman -U nvidia-container-toolkit-1.11.0-1-x86_64.pkg.tar.zst
Missing dependencies: -> libnvidia-container-tools>=1.9.0AUR
wget https://aur.archlinux.org/cgit/aur.git/snapshot/libnvidia-container.tar.gz
tar -xf libnvidia-container.tar.gz && cd libnvidia-container/
makepkg
sudo pacman -U libnvidia-container-1.11.0-1-x86_64.pkg.tar.zst
sudo pacman -U libnvidia-container-tools-1.11.0-1-x86_64.pkg.tar.zst
Missing dependencies: -> bmake, -> rpcsvc-proto
sudo pacman -S bmake rpcsvc-proto
You might also need to re-enable c-groups in /etc/nvidia-container-runtime/config.toml by ensuring no-cgroups is not set to true. And restart Docker:
sudo systemctl restart docker
Testing
At this point, a working setup can be tested by running a base CUDA container. Make sure that you use the image with the same CUDA version that has been installed on the host server above - see nvidia-smi output CUDA Version: 12.4:
docker run --rm --gpus all nvidia/cuda:12.4.0-base-ubuntu20.04 nvidia-smi
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.90.07 Driver Version: 550.90.07 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 1080 Ti Off | 00000000:01:00.0 Off | N/A |
| 33% 32C P8 10W / 250W | 170MiB / 11264MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
| 1 NVIDIA GeForce GTX 1080 Ti Off | 00000000:08:00.0 Off | N/A |
| 33% 30C P8 9W / 250W | 7MiB / 11264MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
+-----------------------------------------------------------------------------------------+
:thumbsup:
Docker Images
docker pull tensorflow/tensorflow:latest-gpu
docker pull pytorch/pytorch:1.13.0-cuda11.6-cudnn8-runtime