LoginSignup
7
10

More than 5 years have passed since last update.

ubuntu 18.04 に、nvidia-docker2をインストールする

Posted at

前提条件

  • ubuntu 18.04
  • NVIDIA製のGPU (GTX7x0=Kepler以降) を搭載
  • NVIDIAのドライバーが動いている (nvidia-smi コマンドが動く)
  • cuda 10.1がインストールされている (cuda 9だと動かない場合がある?)
  • Docker および、NVIDIA Dockerをまだインストールしたことがない
  • sudo のパスワードを知っている

インストール

手順

  1. docker-ce
  2. nvidia-docker2
  3. おまけ

docker-ce 

リンク

パッケージリストを最新の状態に更新する (apt-getでも可ですが、aptのほうがよい)

sudo apt update

前提条件をインストール (スペースで区切りで複数指定, -yをつけると、yes/noを聞かれません)

sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y

Docker公式の公開鍵を取得してインストール

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

鍵が正しいことを確認する

sudo apt-key fingerprint 0EBFCD8

(実行結果として、以下が表示されること)

8pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [  不明  ] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

リポジトリ(パッケージの取得元)を追加

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

リポジトリを追加したので、再度パッケージリストを最新の状態に更新する

sudo apt update

ようやくdocker-ceをインストール

sudo apt install docker-ce docker-ce-cli containerd.io -y

動作確認

sudo docker run hello-world

(実行結果として、以下が表示されること)

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
...

nvidia-docker2

link

nvidia-docker公式の公開鍵を取得してインストール

curl -sL https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -

変数を設定

distribution=$(. /etc/os-release;echo $ID$VERSION_ID)

リポジトリを追加

curl -sL https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list

リポジトリを追加したので、再度パッケージリストを最新の状態に更新する

sudo apt update

ようやくnvidia-docker2をインストール

sudo apt install nvidia-docker2 -y

Dockerデーモンを再起動

sudo pkill -SIGHUP dockerd

動作確認

sudo docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi

(エラーが出た...cudaは10以上でないとダメっぽい? ><)

docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "process_linux.go:424: container init caused \"process_linux.go:407: running prestart hook 1 caused \\\"error running hook: exit status 1, stdout: , stderr: exec command: [/usr/bin/nvidia-container-cli --load-kmods configure --ldconfig=@/sbin/ldconfig.real --device=all --compute --utility --require=cuda>=10.0 brand=tesla,driver>=384,driver<385 --pid=6264 /var/lib/docker/overlay2/9fadbcc1f45b6095d7f3aaf71aa41aa95c13bd61f184dfbc69fe03cb52a69d25/merged]\\\\nnvidia-container-cli: requirement error: unsatisfied condition: brand = tesla\\\\n\\\"\"": unknown.

おまけ

sudoをつけずに、dockerコマンドを実行できるようにする。

sudo gpasswd -a $USER docker
7
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
10