본문 바로가기

[ 프로그래밍 ]

Using NVIDIA/DIGITS with Docker on Ubuntu 16.04

Make sure you have installed the NVIDIA driver and a supported version of Docker for your distribution.



1) Install CUDA on Ubuntu 16.04 [각주:1]


a) Remove Nouveau Driver 


Set Disable Nouveau Driver to avoid conflict with NVidia Driver


$ sudo apt-get remove nvidia* && sudo apt autoremove 

$ sudo apt-get install dkms build-essential linux-headers-generic


Insert as follows in /etc/modprobe.d/blacklist.conf


$ sudo vi /etc/modprobe.d/blacklist.conf


blacklist nouveau 

blacklist lbm-nouveau 

options nouveau modeset=0 

alias nouveau off 

alias lbm-nouveau off


$ echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf


rebuild kernel


$ sudo update-initramfs -u

$ sudo reboot


b) Install Nvidia driver and CUDA


change to console using ctrl + alt + F1 key just after reboot

and EXIT GUI service.


$ sudo service lightdm stop

$ sudo ./cuda_..._linux.run


Insert below 2 lines in ~/.bashrc


export PATH=$PATH:/usr/local/cuda-9.0

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64



2) How To Install and Use Docker on Ubuntu 16.04[각주:2]


a) Installing Docker


First, add the GPG key for the official Docker repository to the system:


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


Add the Docker repository to APT sources:


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


Next, update the package database with the Docker packages from the newly added repo:


$ sudo apt-get update


Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:


$ apt-cache policy docker-ce

$ sudo apt-get install -y docker-ce

$ sudo systemctl status docker


b) Executing the Docker Command without Sudo (optional)


$ sudo usermod -aG docker ${USER}



3) NVIDIA Container Runtime for Docker [각주:3]


a) If you have nvidia-docker 1.0 installed: we need to remove it and all existing GPU containers 


$ docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f 

$ sudo apt-get purge -y nvidia-docker 


b) Add the package repositories 


$ 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 


c) Install nvidia-docker2 and reload the Docker daemon configuration 


$ sudo apt-get install -y nvidia-docker2

$ sudo pkill -SIGHUP dockerd 


d) Test nvidia-smi with the latest official CUDA image 


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



4) TEST MNIST on Docker


make directory to download MNIST dataset (it'll be used in docker)


$ mkdir ~/data


Run DIGITS and download/extract MNIST dataset


$ nvidia-docker run --name digits -d -v ~/data:/data -v ~/digits-jobs:/jobs -p 5000:5000 nvidia/digits && \

docker exec -it digits python -m digits.download_data mnist /data/mnist



    

     









  1. http://www.kwangsiklee.com/2017/07/우분투-16-04에서-cuda-성공적으로-설치하기 [본문으로]
  2. https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04 [본문으로]
  3. https://github.com/NVIDIA/nvidia-docker [본문으로]