DEV Community

Jain Wun
Jain Wun

Posted on

6 3

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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay