DEV Community

Jain Wun
Jain Wun

Posted on

Nvidia Docker安裝說明(含WSL2)


Linux下如果還沒裝過docker的話可以參考

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

curl -fsSL https://get.docker.com -o get-docker.sh
Enter fullscreen mode Exit fullscreen mode
sudo sh get-docker.sh
Enter fullscreen mode Exit fullscreen mode

WSL2

image.png

  • > WSL2在多次更新後也適用和Linux一樣的安裝方式了
  • > 21H2後也不用去安裝特殊版的Nvidia driver了
  • > docker desktop在3.1版後內建支援WSL2上的nvidia-docker

WSL內的Docker也可以用Linux的裝法,但有時候可能會遇到小問題

Linux

要先把nvidia的package server給加進apt的source list

distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
      && 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/$distribution/libnvidia-container.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
Enter fullscreen mode Exit fullscreen mode

然後就可以直接去裝nvidia-docker套件了

sudo apt-get update
sudo apt-get install -y nvidia-docker2
Enter fullscreen mode Exit fullscreen mode

裝好後記得要去把舊有的docker服務給關掉

sudo service docker restart
Enter fullscreen mode Exit fullscreen mode

用Ubuntu裝的話就不用去設定/etc/docker/daemon.json

"default-runtime":"nvidia","runtimes":{"nvidia":{"path":"nvidia-container-runtime","runtimeArgs":[]}}
Enter fullscreen mode Exit fullscreen mode

Test

有多種image可以進行測試,挑一個自己喜歡的就行

最簡單的就是去看nvidia-smi能不能順利運作

sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi
Enter fullscreen mode Exit fullscreen mode

Reference

Installation Guide — NVIDIA Cloud Native Technologies documentation

WSL 2 GPU Support for Docker Desktop on NVIDIA GPUs - Docker

Top comments (0)