iT邦幫忙

0

Nvidia Docker安裝說明(含WSL2)

  • 分享至 

  • xImage
  •  

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

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

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

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

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

sudo apt-get update
sudo apt-get install -y nvidia-docker2

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

sudo service docker restart

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

"default-runtime":"nvidia","runtimes":{"nvidia":{"path":"nvidia-container-runtime","runtimeArgs":[]}}

Test

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

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

sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi

Reference

Installation Guide — NVIDIA Cloud Native Technologies documentation

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


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
cwchiu
iT邦新手 3 級 ‧ 2022-05-20 11:23:13

環境

  • windows 10.0.19043.1706
  • docker desktop 4.8.2
$ apt show nvidia-docker2
Package: nvidia-docker2
Version: 2.10.0-1
Priority: optional
Section: utils
Maintainer: NVIDIA CORPORATION <cudatools@nvidia.com>
Installed-Size: 27.6 kB
Depends: nvidia-container-toolkit (>= 1.9.0-1), docker-ce (>= 18.06.0~ce~3-0~ubuntu) | docker-ee (>= 18.06.0~ce~3-0~ubuntu) | docker.io (>= 18.06.0)
Breaks: nvidia-docker (<< 2.0.0)
Replaces: nvidia-docker (<< 2.0.0)
Homepage: https://github.com/NVIDIA/nvidia-docker/wiki
Download-Size: 5532 B
APT-Manual-Installed: yes
APT-Sources: https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64  Packages
Description: nvidia-docker CLI wrapper
 Replaces nvidia-docker with a new implementation based on the NVIDIA Container Toolkit
 
$ sudo nvidia-container-cli --load-kmods info
Segmentation fault

$ sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: Running hook #0:: error running hook: signal: segmentation fault, stdout: , stderr:: unknown.

$ docker run -it --gpus=all --rm nvidia/cuda:11.4.2-base-ubuntu20.04 nvidia-smi
docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: Running hook #0:: error running hook: signal: segmentation fault, stdout: , stderr:: unknown.

runtime 也沒看到 nvidia

$ docker info | grep runtime
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc

如何排除?

增廣建文 iT邦研究生 5 級 ‧ 2022-05-22 23:10:06 檢舉

這不是21H2吧 win10只有21H2能用

增廣建文 iT邦研究生 5 級 ‧ 2022-05-22 23:12:40 檢舉

21H2的OS build number應該會>=10.0.19044

cwchiu iT邦新手 3 級 ‧ 2022-05-27 11:03:01 檢舉

你是對的我的只有到 21H1. 等升級21H2後再來驗證. 謝謝你的回覆

我要留言

立即登入留言