uni memo

dockerでgpuコンテナの作成

dockerでgpuコンテナの作成

docker19.03でdockerコマンドでgpuコンテナを作成できるようになったらしいので試した まあまあ大変だったので残しておく

環境

  • ubuntu: 18.04
  • docker: 19.03

エラー

ホストマシンにdockerとnvidia-smiを入れてから以下を実行したらエラーがでた、

docker run -it --rm --gpus all ubuntu nvidia-smi
docker: Error response from daemon: linux runtime spec devices: could not select device driver "" with capabilities: [[gpu]].

↓を参考にやっていったらできたので手順を書いておく

http://collabnix.com/introducing-new-docker-cli-api-support-for-nvidia-gpus-under-docker-engine-19-03-0-beta-release/

install

driversを入れて、再起動

apt-get install ubuntu-drivers-common \
	&& sudo ubuntu-drivers autoinstall

reboot

以下のスクリプトを作成し、実行する

vi nvidia-container-runtime-script.sh

内容は以下

curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \
  sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update
Execute the script

実行

sh nvidia-container-runtime-script.sh
sudo apt-get install nvidia-container-runtime

docker19.03を入れる

curl -fsSL https://test.docker.com -o test-docker.sh 

sh test-docker.sh

コンテナ作成、確認

docker run -it --rm --gpus all ubuntu nvidia-smi

Wed Aug  7 15:57:09 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.26       Driver Version: 430.26       CUDA Version: N/A      |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1050    Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   58C    P0    N/A /  N/A |    880MiB /  4042MiB |     23%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

参考

2024, Built with Gatsby. This site uses Google Analytics.