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 nvidia nvidia-utils nvidia-settings opencl-nvidia xorg-server-devel
reboot
Verify that the installation worked:
sudo nvidia-smi
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.14 Driver Version: 550.54.14 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 1060 Off | 00000000:01:00.0 Off | N/A |
| N/A 50C P8 4W / 78W | 6MiB / 6144MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 709 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.0
AUR
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:
docker run --rm --gpus all nvidia/cuda:12.3.2-base-ubuntu22.04 nvidia-smi
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.14 Driver Version: 550.54.14 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 1060 Off | 00000000:01:00.0 Off | N/A |
| N/A 50C P8 6W / 78W | 6MiB / 6144MiB | 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