[LINUX] How to create an NVIDIA Docker environment


Note how to create an NVIDIA Docker environment as of November 4, 2020. Before I knew it, CUDA was not recognized, so I decided to re-install it from the driver.

Wed Nov  4 14:41:54 2020       
| NVIDIA-SMI 430.64       Driver Version: 430.64       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 108...  Off  | 00000000:01:00.0  On |                  N/A |
|  0%   35C    P8    12W / 275W |     62MiB / 11175MiB |      0%      Default |
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|    0      1609      G   /usr/lib/xorg/Xorg                            59MiB |

Erase the old environment

#Uninstall current CUDA
$ sudo apt purge cuda*
$ sudo apt purge nvidia-cuda-*
$ sudo apt purge libcuda*
#Completely deleted
$ sudo apt-get purge nvidia*
$ sudo apt-get autoremove
$ sudo apt-get autoclean
$ sudo rm -rf /usr/local/cuda*

Main subject

You can install CUDA, Docker, and nvidia-docker2 by following the 3 steps below. Until now, the Nvidia Driver was installed separately, but if you install CUDA, the corresponding driver will also be installed.

1. Install the latest CUDA driver

Install according to the CUDA Toolkit website (https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=debnetwork)

$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-ubuntu1604.pin
$ sudo mv cuda-ubuntu1604.pin /etc/apt/preferences.d/cuda-repository-pin-600
$ sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
$ sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/ /"
$ sudo apt-get update
$ sudo apt-get -y install cuda #(* When specifying the version, cuda-10-Write like 2)

2. Install Docker

Install according to Docker official installation method

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

After installation, start docker service and set automatic start

$ sudo systemctl start docker && sudo systemctl enable docker

If you want the docker command to be executable without sudo, add the target user to the docker group as follows:

$ sudo usermod -aG docker $USER

3. Install the NVIDIA Container Toolkit (nvidia-docker2) package

Install according to Official installation method

$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
   && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \
   && 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
$ sudo apt-get install -y nvidia-docker2
$ sudo systemctl restart docker

After restarting, check the operation

$ sudo reboot
$ nvidia-smi

Complete when Nvidia Driver and CUDA Version are displayed.

Reference [What's going on with NVIDIA Docker now? (20.09 version)](https://medium.com/nvidiajapan/nvidia-docker-%E3%81%A3%E3%81%A6%E4%BB%8A%E3%81%A9%E3%81%86 % E3% 81% AA% E3% 81% A3% E3% 81% A6% E3% 82% 8B% E3% 81% AE-20-09-% E7% 89% 88-558fae883f44)

Recommended Posts

How to create an NVIDIA Docker environment
How to create an email user
How to use tensorflow under docker environment
Introduction to docker Create ubuntu environment in ubuntu
How to create a Python virtual environment (venv)
How to create an OCF compliant resource agent
[Note] How to create a Ruby development environment
[Note] How to create a Mac development environment
How to create an article from the command line
Create an environment with virtualenv
[Blender x Python] How to create an original object
How to build a Django (python) environment on docker
How to create an image uploader in Bottle (Python)
Create an environment for "Deep Learning from scratch" with Docker
Minimum Makefile and buildout.cfg to create an environment with buildout
Introducing Kaggle's Docker Image on Windows to build an environment
Create a Todo app with Django ① Build an environment with Docker
[Python Kivy] How to create an exe file with pyinstaller
How to create an ISO file (CD image) on Linux
[Django] Memo to create an environment of Django + MySQL + Vue.js [Python]
Overview of Python virtual environment and how to create it
How to create a Conda package
How to create your own Transform
How to create a virtual bridge
How to create / delete symbolic links
How to create a Dockerfile (basic)
How to delete a Docker container
How to write Docker base image
How to create a config file
How to log in to Docker + NGINX
I tried to create an environment of MkDocs on Amazon Linux
How to debug Dash (Flask) in Docker + VSCode + remote connection environment
How to create a heatmap with an arbitrary domain in Python
How to use jupyter notebook without polluting your environment with Docker
Create an arbitrary machine learning environment with GCP + Docker + Jupyter Lab
Learn how to use Docker through building a Django + MySQL environment
How to easily create an environment where python code runs on Jupyter without polluting the local environment
How to create a clone from Github
How to access environment variables in Python
How to build a sphinx translation environment
How to create a git clone folder
python3 How to install an external module
How to create * .spec files for pyinstaller.
How to convert Python to an exe file
I created an Anaconda environment using Docker!
How to prepare Python development environment [Mac]
Create Python + uWSGI + Nginx environment with Docker
Create an OpenCV3 + python3 environment on OSX
How to create a repository from media
How to add python module to anaconda environment
How to install python3 with docker centos
Prepare an environment to touch grib2 format files with python (Docker edition)
[Development environment] How to create a data set close to the production DB
How to create sample CSV data with hypothesis
How to make an embedded Linux device driver (11)
How to create large files at high speed
How to share a virtual environment [About requirements.txt]
For beginners to build an Anaconda environment. (Memo)
How to build an environment when you want to use python2.7 after installing Anaconda3
How to make an embedded Linux device driver (1)
How to make an embedded Linux device driver (4)