Skip to content

Instantly share code, notes, and snippets.

@JuanM04
Last active April 23, 2023 20:23
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanM04/fcbed16d0f4405a286adebee5fd31cb2 to your computer and use it in GitHub Desktop.
Save JuanM04/fcbed16d0f4405a286adebee5fd31cb2 to your computer and use it in GitHub Desktop.
Install NVIDIA Container Toolkit on Fedora

Install NVIDIA Container Toolkit on Fedora

Last Updated: 2021-06-27
Tested on Fedora 34 (5.12.12-300.fc34.x86_64)

Install NVIDIA Drivers

First, add the RPM Fusion repositories:

sudo dnf update
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Next, install the drivers. You can use this tool to look up the version you need. If you don't know which GPU do you have, you can run lspci -vnn | grep VGA.

sudo dnf install xorg-x11-drv-nvidia-cuda akmod-nvidia # 400 or higher
sudo dnf install xorg-x11-drv-nvidia-390xx akmod-nvidia-390xx
sudo dnf install xorg-x11-drv-nvidia-340xx akmod-nvidia-340xx

Install NVIDIA Container Toolkit

Add the NVIDIA repos:

curl -s -L https://nvidia.github.io/nvidia-docker/centos8/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo
# If you version of Fedora is based on RHEL 7 (or if it's older than Fedora 28), replace `centos8` by `centos7`

Install nvidia-docker:

sudo dnf clean expire-cache --refresh
sudo dnf install -y nvidia-docker2

Disable cgroups:

# /etc/nvidia-container-runtime/config.toml

[nvidia-container-cli]
no-cgroups = true

Restart Docker and test:

sudo systemctl restart docker
sudo docker run --rm --gpus all --privileged nvidia/cuda:11.3.1-base nvidia-smi

You should get an output like this:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 465.31       Driver Version: 465.31       CUDA Version: 11.3     |
|-------------------------------+----------------------+----------------------+
| 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 ...  Off  | 00000000:26:00.0  On |                  N/A |
|  0%   44C    P8    11W / 160W |    496MiB /  5931MiB |      3%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

Usage

If you want to use your NVIDIA GPU in a Docker container, you need to add the flags --gpus all and --privileged.


References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment