Proxmox上のUbuntuにNvidiaのドライバーをインストールしてDockerで使用する
今回は、Proxmox上のUbuntuにNvidiaのドライバーをインストールして、Docker上で使用するまでの方法を記載します。
Difyを使ってみたかったので、インストールしましたー
実行環境
CPU:i7-13700K
MEM:64GB
GPU:Geforce RTX4090
Proxmox:8.4.1
OS:Ubuntu 25.04
VMの作成
VMを作成する際、いくつかの設定画必要なので注意する。
System設定
Graphic card: Default → VirtIO-GPU
Machine: Default → q35
BIOS: Default → OVMF (UEFI)
VM作成後にPCIEデバイスを追加
RAW Deviceを選択し、Primary GPU, ALL Functions, ROM-Bar, PCI-Expressに
チェックを入れる。
Ubuntuのインストール
Ubuntuのインストールは通常通り行う。
Nvidia GPU Driverのインストール
まずは、デフォルトでインストールされているGPUドライバーをアンインストールする。
sudo apt-get --purge remove nvidia-*
sudo apt-get --purge remove cuda-*
次に、利用可能なGPUドライバーを確認する。
ubuntu-drivers devices
こんな感じで出てきます。
が、なぜか、570も535もだめで、560だと上手くいきました。
「nvidia-driver-560」をインストールしてきます。
== /sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0 ==
modalias : pci:v000010DEd00002684sv00001569sd0000F296bc03sc00i00
vendor : NVIDIA Corporation
model : AD102 [GeForce RTX 4090]
driver : nvidia-driver-570-open - distro non-free recommended
driver : nvidia-driver-535-server-open - distro non-free
driver : nvidia-driver-570 - distro non-free
driver : nvidia-driver-535-server - distro non-free
driver : nvidia-driver-570-server - distro non-free
driver : nvidia-driver-570-server-open - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
apt install nvidia-driver-570
今回は、UEFI環境で実行してるので、インストールの途中でパスワードを設定する必要があります。
パスワードを設定してください。(確認も含め2回入力)
インストールがおわったら再起動します。
再起動する際は、ssh接続などでは無く、Proxmoxのコンソールから画面を見ながら再起動しましょう。
(画面をいじる必要があるので)
再起動後、以下の様な画面が出てくるので、「Enroll MOK」を選択します。
「Continue」をクリックします。
「Enroll the key(s)?」と聞かれるので、「Yes」を選択します。
パスワードを聞かれるので、先ほど聞かれたパスワードを入力します。
「Reboot」を選択します。
インストールが出来ていることを確認するため、以下のコマンドを実行します。
nvidia-smi
GPUの情報が色々表示されたら、完了です。
NVIDIA Container Toolkitのインストール
次に、「NVIDIA Container Toolkit」をインストールしていきます。
基本的には、以下のウェブサイトの通りにコマンドを実行していけば、インストール出来ます。
レポジトリを追加します。
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
updateします。
sudo apt-get update
バージョンを指定して、Toolkitをインストールします。
export NVIDIA_CONTAINER_TOOLKIT_VERSION=1.17.8-1
sudo apt-get install -y \
nvidia-container-toolkit=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
nvidia-container-toolkit-base=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
libnvidia-container-tools=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
libnvidia-container1=${NVIDIA_CONTAINER_TOOLKIT_VERSION}
Dockerのインストール
Dockerも以下のウェブサイトに従って、インストールします。
レポジトリの追加
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
インストール
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Docker上でGPUを認識させる
以下のコマンドを実行して、Docker上でGPUを認識させる。
sudo nvidia-ctk runtime configure --runtime=docker
Dockerを再起動する。
systemctl restart docker
Docker上でGPUが動作するかの確認
Docker上でGPUが動作するか確認するため、以下のDockerコンテナを実行します。
参考:https://zenn.dev/usagi1975/articles/2023-02-18-1400_docker-gpu-bench
docker run --rm --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark -numbodies=640000
以下の様な実行結果が出たら完了
Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance.
-fullscreen (run n-body simulation in fullscreen mode)
-fp64 (use double precision floating point values for simulation)
-hostmem (stores simulation data in host memory)
-benchmark (run benchmark to measure performance)
-numbodies=<N> (number of bodies (>= 1) to run in simulation)
-device=<d> (where d=0,1,2.... for the CUDA device to use)
-numdevices=<i> (where i=(number of CUDA devices > 0) to use for simulation)
-compare (compares simulation results running once on the default GPU and once on the CPU)
-cpu (run n-body simulation on the CPU)
-tipsy=<file.bin> (load a tipsy model file for simulation)
NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.
> Windowed mode
> Simulation data stored in video memory
> Single precision floating point simulation
> 1 Devices used for simulation
MapSMtoCores for SM 8.9 is undefined. Default to use 128 Cores/SM
MapSMtoArchName for SM 8.9 is undefined. Default to use Ampere
GPU Device 0: "Ampere" with compute capability 8.9
> Compute 8.9 CUDA device: [NVIDIA GeForce RTX 4090]
number of bodies = 640000
640000 bodies, total time for 10 iterations: 1976.248 ms
= 2072.614 billion interactions per second
= 41452.281 single-precision GFLOP/s at 20 flops per interaction
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error running prestart hook #0: exit status 1, stdout: , stderr: Auto-detected mode as 'legacy'
Discussion