プログラミングとかLinuxとかの備忘録

プログラミング、Linuxでハマった箇所や環境構築のメモ

Ubuntu16.04でnvidia-dockerを動かす

構成

初期設定

ネットワーク

$ sudo apt-get -y install resolvconf

$ sudo nmcli con mod eno1 ipv4.method manual
$ sudo nmcli con mod eno1 ipv4.address 192.168.1.23/24
$ sudo nmcli con mod eno1 ipv4.dns 192.168.1.1
$ sudo nmcli con mod eno1 ipv4.gateway 192.168.1.1

$ sudo nmcli con down eno1 && sudo nmcli con up eno1

アップデート

$ sudo apt-get update
$ sudo apt-get -y upgrade
$ sudo apt-get -y dist-upgrade

OpenSSHのインストール

$ sudo apt-get -y install openssh-server

$ sudo systemctl start sshd
$ sudo systemctl enable sshd

CUDA

確認

以下のコマンドで,何も出てこないことを確認する

$ sudo dpkg -l | grep nvidia
$ sudo dpkg -l | grep cuda

Nvidiaドライバのインストール

リポジトリ(Proprietary GPU Drivers : “Graphics Drivers” team)
を登録して,ドライバをインストールする
途中で,secure bootを無効にするかを聞かれたが,無効にせずに続行した

$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt-get update

$ sudo apt-get -y install nvidia-387

再起動し,GPUが認識されているかを確認

$ sudo reboot

$ nvidia-smi
Sat Dec  9 10:19:09 2017       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 387.34                 Driver Version: 387.34                    |
|-------------------------------+----------------------+----------------------+
| 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 106...  Off  | 00000000:01:00.0  On |                  N/A |
|  0%   37C    P8     6W / 156W |     91MiB /  6071MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1130      G   /usr/lib/xorg/Xorg                            89MiB |
+-----------------------------------------------------------------------------+

dockerのインストール

Ubuntu公式リポジトリdocker.ioではnvidia-dockerを実行できない (docker-engine, docker-ce, docker-eeのいずれかのパッケージが依存関係として必要) ので、Get Docker CE for Ubuntu | Docker Documentation の通りにインストールする

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update

$ sudo apt-get -y install docker-ce

nvidia-dockerのインストール

GitHub - NVIDIA/nvidia-docker: Build and run Docker containers leveraging NVIDIA GPUsの通りにインストールする

$ sudo apt-get -y install curl

$ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
$ curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu16.04/amd64/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
$ sudo apt-get update

$ sudo apt-get install -y nvidia-docker2
$ sudo pkill -SIGHUP dockerd

テスト(nvidia-docker run --rm nvidia/cuda nvidia-smiでもいける)

$ docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
Unable to find image 'nvidia/cuda:latest' locally
latest: Pulling from nvidia/cuda
660c48dd555d: Pull complete
4c7380416e78: Pull complete
421e436b5f80: Pull complete
e4ce6c3651b3: Pull complete
be588e74bd34: Pull complete
f597507b3c37: Pull complete
9c5d4127a23d: Pull complete
398bf259fcdc: Pull complete
4f4092762618: Pull complete
94130a21e154: Pull complete
Digest: sha256:954c82d2d060f38de13b3d7933b7e1549b25330cc6412008dc1253f3c148448d
Status: Downloaded newer image for nvidia/cuda:latest
Sat Dec  9 01:59:36 2017       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 387.34                 Driver Version: 387.34                    |
|-------------------------------+----------------------+----------------------+
| 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 106...  Off  | 00000000:01:00.0  On |                  N/A |
|  0%   37C    P8     6W / 156W |     91MiB /  6071MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

Debian StretchでNFSサーバを動かす

インストール

$ sudo apt -y install nfs-kernel-server

共有ディレクトリの設定

NFSv4で共有するように/etc/exportsを編集する。
/srv/nfs4NFSのルートにし、shareを公開する。

$ sudo vim /etc/exports
/srv/nfs4         192.168.1.0/24(rw,async,fsid=0,crossmnt,no_root_squash)
/srv/nfs4/share   192.168.1.0/24(rw,async,no_root_squash)

共有ディレクトリのバインドマウント

ディレクトリ作成

$ sudo mkdir -p /srv/nfs4/share

/etc/fstabの編集、マウント

$ sudo vim /etc/fstab
/mnt/hdd    /srv/nfs4/share    none    bind    0 0

$ sudo mount -a

サービス起動

$ sudo systemctl start nfs-server
$ sudo systemctl enable nfs-server

公開状態の確認

$  sudo exportfs
/srv/nfs4       192.168.1.0/24
/srv/nfs4/share
                192.168.17.0/24

クライアント側からは下記コマンドでマウントできる

$ sudo mount.nfs <NFSサーバIP>:/ /mnt

$ ls /mnt
share

Arch Linuxのインストール 2019年6月版

Install

インストールガイド - ArchWiki を参考に進める

$ ls /sys/firmware/efi/efivars
$ loadkeys jp106

...
$ parted /dev/sda
(parted)$ mklabel gpt
(parted)$ mkpart ESP fat32 1MiB 513MiB
(parted)$ set 1 boot on
(parted)$ mkpart primary xfs 513MiB 100%
(parted)$ print
Number Start  End   Size  File system Name Flags
 1     1049kB 538MB 537MB fat32            boot, esp
 2     538MB  120GB 119GB xfs
(parted)$ quit

$ mkfs.fat -F32 /dev/sda1
$ mkfs.xfs /dev/sda2

$ mount /dev/sda2 /mnt
$ mkdir /mnt/boot
$ mount /dev/sda1 /mnt/boot
$ ping archlinuxjp.org
...ok

$ timedatectl set-ntp true

$ vim /etc/pacman.d/mirrorlist
## Japan
http://ftp.tsukuba.wide.ad.jp/Linux/archlinux/$repo/os/$arch
http://ftp.jaist.ac.jp/pub/Linux/ArchLinux/$repo/os/$arch

$ pacstrap /mnt base base-devel

$ genfstab -U /mnt >> /mnt/etc/fstab
$ arch-chroot /mnt
$ ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
$ hwclock --systohc --utc

$ pacman -S vim

$ vim /etc/locale.gen
en_US.UTF-8 UTF-8
ja_JP.UTF-8 UTF-8
$ locale-gen
Generating locales...
  en_US.UTF-8... done
  ja_JP.UTF-8... done
Generation complete.

$ echo LANG=en_US.UTF-8 > /etc/locale.conf
$ echo KEYMAP=jp106 > /etc/vconsole.conf
$ echo ホスト名 > /etc/hostname
$ vim /etc/hosts
127.0.1.1   ホスト名.localdomain    ホスト名

$ mkinitcpio -p linux

rootパスワードの設定

$ passwd

ブートローダのインストール

$ ls /sys/firmware/efi/efivars

これで色々出てくれば大丈夫。

$ bootctl --path=/boot install
$ vim /boot/loader/loader.conf
default arch
timeout 3
editor 0

$ blkid -s PARTUUID -o value /dev/sda2
UUID文字列
$ vim /boot/loader/entries/arch.conf
title   Arch Linux
linux   /vmlinuz-linux
initrd  /initramfs-linux.img
options root=PARTUUID=UUID文字列 rw

$ exit
$ umount -R /mnt
$ reboot

初期設定

ユーザ追加・sudo有効化

$ useradd --create-home ユーザ名
$ gpasswd -a ユーザ名 wheel
$ passwd ユーザ名

$ pacman -S sudo
$ EDITOR=vim visudo
%wheel ALL=(ALL) ALL    # コメント解除する

これ以降はユーザ権限で設定を行う

DHCP有効化

デフォルトで起動しているものと思っていたが,起動していなかったので

$ sudo systemctl start dhcpcd

yay

yaourtが開発停止になったため代わりのyayを入れる

$ sudo pacman -S git

$ git clone https://aur.archlinux.org/yay.git
$ cd yay
$ makepkg -si

$ type yay
yay is /usr/bin/yay
$ yay --version
yay v9.2.0 - libalpm v11.0.3

AURを追加する

$ sudo vim /etc/pacman.conf
[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch

$ yay -Syy

GUIのインストール

Xorg、LightDM、Xfceをインストールする

$ sudo pacman -S \
    xorg-server xorg-xclock xterm \
    lightdm lightdm-gtk-greeter \
    xfce4 xfce4-goodies

$ sudo systemctl enable lightdm

グラフィックスドライバを入れる

$ lspci | grep -e VGA -e 3D
%%%%%
%%%%%
%%%%%
$ sudo pacman -S xf86-video-intel

xf86-video-*は環境に合わせてamdgpuとかnouveauに変える。

グラフィックドライバをロードするために再起動する。

$ sudo reboot

再起動後はLightDMが動いてGUIログインできる。

キーボードレイアウトの設定

Xorg でのキーボード設定 - ArchWiki

$ sudo vim /etc/X11/xorg.conf.d/00-keyboard.conf
Section "InputClass"
    Identifier "system-keyboard"
    MatchIsKeyboard "on"
    Option "XkbLayout" "jp,us"
    Option "XkbModel" "pc106"
    Option "XkbVariant" ",dvorak"
    Option "XkbOptions" "grp:alt_shift_toggle"
EndSection

$ sudo reboot

日本語入力

xprofile - ArchWiki

$ sudo pacman -S \
    fcitx-mozc fcitx-im fcitx-configtool \
    noto-fonts-cjk

$ vim ~/.xprofile
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=”@im=fcitx”

$ vim ~/.xinitrc
[ -f /etc/xprofile ] && . /etc/xprofile
[ -f ~/.xprofile ] && . ~/.xprofile
fcitx-autostart &

ログインし直して、タスクバーのキーボードアイコンから、
Configureを選択し、+アイコンからMozcを追加する。

ScalaFXで作成したアプリケーションが実行できない

環境

  • Fedora27 (Docker) on ArchLinux
  • Intellij IDEA 2018.1.5
  • Scala 2.12.4
  • Java8
    • OpenJDK 1.8.0_171-b10
    • OracleJDK 1.8.0_172-b11

エラー内容

  • ScalaFXでGUIソフトを作成し、RUN -> RUN 'Main'すると下記エラーが出て実行できなかった(コンパイルは正常終了)
  • OpenJDKでもOracleJDKでも同じエラーが出た
Graphics Device initialization failed for :  es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:280)
        at com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:221)
        at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:248)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:209)
        at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:675)
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:695)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:94)
        at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
        ... 1 more
Exception in thread "main" java.lang.RuntimeException: No toolkit found
        at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:260)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:209)
        at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:675)
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:695)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
        at java.lang.Thread.run(Thread.java:748)

調べてみる

下記はOracleJDK 1.8.0_172-b11で実行した。

java - JavaFX on Linux is showing a "Graphics Device initialization failed for : es2, sw" - Stack Overflow
の通りに-Dprism.verbose=trueをつけて実行してみる

RUN -> RUN... -> Edit ConfigurationVM options-Dprism.verbose=trueを追加して実行する

Prism pipeline init order: es2 sw 
Using java-based Pisces rasterizer
Using dirty region optimizations
Not using texture mask for primitives
Not forcing power of 2 sizes for textures
Using hardware CLAMP_TO_ZERO mode
Opting in for HiDPI pixel scaling
Prism pipeline name = com.sun.prism.es2.ES2Pipeline
Loading ES2 native library ... prism_es2
GraphicsPipeline.createPipeline failed for com.sun.prism.es2.ES2Pipeline
java.lang.UnsatisfiedLinkError: /usr/java/jdk1.8.0_172-amd64/jre/lib/amd64/libprism_es2.so: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
(省略)

libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directoryということなので

$ dnf -y install gtk2

次は、libXxf86vm.so.1: cannot open shared object file: No such file or directoryなので

$ dnf -y install libXxf86vm

次は、libGL.so.1: cannot open shared object file: No such fileなので

$ dnf -y install mesa-libGL

再度実行してみると下記のエラーが出た

libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
Prism ES2 Error - nInitialize: glXChooseFBConfig failed
(X) Got class = class com.sun.prism.es2.ES2Pipeline
GraphicsPipeline.createPipeline: error initializing pipeline com.sun.prism.es2.ES2Pipeline
*** Fallback to Prism SW pipeline
Prism pipeline name = com.sun.prism.sw.SWPipeline
(X) Got class = class com.sun.prism.sw.SWPipeline
Initialized prism pipeline: com.sun.prism.sw.SWPipeline
 vsync: true vpipe: false
Error: JavaFX detected no fonts! Please refer to release notes for proper font configuration
Exception in Application start method
(省略)

TrueTypeフォントを探して入れる

$ dnf -y search fonts | grep TrueType | grep Japanese
sazanami-fonts-common.noarch : Common files for Sazanami Japanese TrueType fonts
motoya-lcedar-fonts.noarch : Japanese Gothic-typeface TrueType fonts by MOTOYA
motoya-lmaru-fonts.noarch : Japanese Round Gothic-typeface TrueType fonts by
hanazono-fonts.noarch : Japanese Mincho-typeface TrueType font
vlgothic-fonts.noarch : Japanese TrueType font
vlgothic-p-fonts.noarch : Proportional Japanese TrueType font
sazanami-gothic-fonts.noarch : Sazanami Gothic Japanese TrueType font
sazanami-mincho-fonts.noarch : Sazanami Mincho Japanese TrueType font

$ dnf -y install vlgothic-fonts

ここで実行すると、下記のエラーが出たがとりあえず動くようになった。

libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
Prism ES2 Error - nInitialize: glXChooseFBConfig failed
GraphicsPipeline.createPipeline: error initializing pipeline com.sun.prism.es2.ES2Pipeline
*** Fallback to Prism SW pipeline
(省略)
 vsync: true vpipe: false
QuantumRenderer: shutdown

解決方法まとめ

$ dnf -y install gtk2 libXxf86vm mesa-libGL vlgothic-fonts

しておけばOpenJDKでもOracleJDKでも動いた。

ただしOpenJDKの場合は、下記のOpenJFX関連の設定が必要だった

$ dnf -y install java-1.8.0-openjdk-openjfx-devel
$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib/jvm/openjfx/rt/lib/amd64
$ cp /usr/lib/jvm/openjfx/rt/lib/ext/jfxrt.jar <プロジェクトルート>/lib/

Ubuntu16.04でVirtualBoxを動かす

実行環境

  • OS : Ubuntu16.04.4 LTS
  • CPU: Ryzen Threadripper 1950X
  • M/B: ASUS PRIME-X399-A

インストール

$ sudo apt-get -y install virtualbox

仮想マシンを起動してみる

$ virtualbox

別マシンで作成したWindows7の仮想HDD(Win7Test)を指定して起動すると、ポップアップで下記内容が表示されて起動に失敗する

Failed to open a session for the virtual machine Win7Test.

AMD-V is disabled in the BIOS (or by the host OS) (VERR_SVM_DISABLED).

Result Code: NS_ERROR_FAILURE (0x80004005)
Component : ConsoleWrap
Interface : IConsole {872da645-4a9b-1727-bee2-5585105b9eed}

AMD-Vが無効になっている

仮想化機能の確認

ハードウェアがサポートしているか

されている

$ LC_ALL=C lscpu | grep Virtualization
Virtualization:        AMD-V

OSからAMD-Vが利用可能か

Intelでやったときkvm_intelが出てきていたが,kvm_amdみたいなのが無いのでBIOSカーネルかで無効になっている?

$ lsmod | grep kvm
kvm                   552960  0
irqbypass              16384  1 kvm

マザーボードで有効化されているか

Advanced -> CPU Configuration -> SVM Modeで有効化(Disabled -> Enabledに変更)する必要があった

再起動するとkvm_amdが追加された

$ lsmod | grep kvm
kvm_amd                65536  0
kvm                   552960  1 kvm_amd
irqbypass              16384  1 kvm

kvm_amdが追加された状態ならエラーなしで仮想マシンを起動できた

Ubuntu16.04にsambaサーバを立てる

インストール

$ sudo apt-get -y install samba

設定ファイル編集

$ sudo vim /etc/samba/smb.conf

で設定ファイルを編集する

globalセクション

[global]
        unix charset = UTF-8
        dos charset = CP932
        writable = yes
        guest ok = no
        vfs objects = recycle
        recycle:repository = .recycle
        recycle:keeptree = no
        recycle:touch = yes
        recycle:versions = yes
        recycle:maxsize = 0

homesセクション

# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each
# user's home directory as \\server\username
[homes]
   comment = Home Directories
   browseable = yes
# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
;   read only = yes
    read only = no
# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
;   create mask = 0700
# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
;   directory mask = 0700
# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# Un-comment the following parameter to make sure that only "username"
# can connect to \\server\username
# This might need tweaking when using external authentication schemes
    valid users = %S

プリンタ

不要なので無効にする

;[printers]
;   comment = All Printers
;   browseable = no
;   path = /var/spool/samba
;   printable = yes
;   guest ok = no
;   read only = yes
;   create mask = 0700
;
;# Windows clients look for this share name as a source of downloadable
;# printer drivers
;[print$]
;   comment = Printer Drivers
;   path = /var/lib/samba/printers
;   browseable = yes
;   read only = yes
;   guest ok = no

サービス起動

$ sudo systemctl start smbd nmbd
$ sudo systemctl enable smbd nmbd

Sambaユーザの追加

下記コマンドでユーザを追加できる。
追加後にサービスを再起動する必要はない。

$ sudo smbpasswd -a ユーザ名
New SMB password: パスワード入力
Retype new SMB password: パスワード再入力
Added user ユーザ名.

UbuntuServer16.04でnvidia-dockerを動かす

UbuntuServer16.04でnvidia-dockerを動かす

構成

  • UbuntuServer 16.04.4 LTS
  • GTX1080ti *1

確認

以下のコマンドで,何も出てこないことを確認する

$ sudo dpkg -l | grep nvidia
$ sudo dpkg -l | grep cuda

Nvidiaドライバのインストール

リポジトリ(Proprietary GPU Drivers : “Graphics Drivers” team)
を登録して,ドライバをインストールする

$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update

$ sudo apt -y install nvidia-396

再起動し,

$ sudo reboot

GPUが認識されているかを確認

$ nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 396.18                 Driver Version: 396.18                    |
|-------------------------------+----------------------+----------------------+
| 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 108...  Off  | 00000000:41:00.0  On |                  N/A |
| 29%   43C    P0    59W / 250W |     59MiB / 11164MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1594      G   /usr/lib/xorg/Xorg                            56MiB |
+-----------------------------------------------------------------------------+

dockerのインストール

Ubuntu公式リポジトリdocker.ioではnvidia-dockerを実行できない (docker-engine, docker-ce, docker-eeのいずれかのパッケージが依存関係として必要) ので、Get Docker CE for Ubuntu | Docker Documentation の通りにインストールする

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update

$ sudo apt-get -y install docker-ce

ユーザをdockerグループに追加し、ログインし直すとsudo無しでdockerを実行できるようになる

$ sudo gpasswd -a ユーザ名 docker

## logout & login

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nvidia-dockerのインストール

GitHub - NVIDIA/nvidia-docker: Build and run Docker containers leveraging NVIDIA GPUsの通りにインストールする

GPGキーの追加

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

リポジトリの追加

$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
$ sudo apt-get update

nvidia-dockerのインストール

$ sudo apt-get -y install nvidia-docker2
$ sudo pkill -SIGHUP dockerd

テスト

$ docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
Unable to find image 'nvidia/cuda:latest' locally
latest: Pulling from nvidia/cuda
d3938036b19c: Pull complete
a9b30c108bda: Pull complete
67de21feec18: Pull complete
817da545be2b: Pull complete
d967c497ce23: Pull complete
5ddeb439bad8: Pull complete
c6496427ad3b: Pull complete
360fde1360ca: Pull complete
4cc434a95aa2: Pull complete
e5c0eee6e0d5: Pull complete
Digest: sha256:d17a4683f1554de305741e55886d5835b204f602ca73a0df83e02afeb313db76
Status: Downloaded newer image for nvidia/cuda:latest
Thu Apr 19 08:35:27 2018
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 396.18                 Driver Version: 396.18                    |
|-------------------------------+----------------------+----------------------+
| 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 108...  Off  | 00000000:41:00.0  On |                  N/A |
| 29%   32C    P8    10W / 250W |     59MiB / 11164MiB |      1%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

動いた