---
# System prepended metadata

title: Install nvidia docker
tags: [Docker, tutorial]

---

# Install nvidia docker
###### tags: `Docker` `tutorial`

[TOC]

![](https://i.imgur.com/n90UaWd.png)

### 1. install docker
```
sudo apt update && sudo apt-get install -y \
    apt-transport-https \
    ca-certificates curl \
    gnupg-agent \
    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"

###
### docker-ce 19.03.8 has issue when setting storage-opt
###

sudo apt-get update && sudo apt-get install -y \
    docker-ce=5:19.03.5~3-0~ubuntu-bionic \
    docker-ce-cli \
    containerd.io

sudo pkill -SIGHUP dockerd
```

### 2. Change docker storage path
```
(optional) sudo mkdir /mnt/sdb/docker
sudo systemctl stop docker
sudo rsync -aqxP /var/lib/docker /mnt/sdb/docker
sudo mount --rbind /mnt/sdb/docker /var/lib/docker
sudo systemctl start docker

```

Edit fstab

```
sudo vi /etc/fstab
```

```
/mnt/sdb/docker /var/lib/docker none defaults,bind 0 0
```

### 3. install NVIDIA driver
```
sudo apt-get install -y build-essential gcc-multilib dkms

sudo bash -c "echo blacklist nouveau > \
/etc/modprobe.d/blacklist-nvidia-nouveau.conf"

sudo bash -c "echo options nouveau modeset=0 >> \
/etc/modprobe.d/blacklist-nvidia-nouveau.conf"
```
```
sudo wget http://us.download.nvidia.com/\
XFree86/Linux-x86_64/440.64/NVIDIA-Linux-x86_64-440.64.run

chmod +x NVIDIA-*; sudo bash ./NVIDIA-*.run
#all enter for default
```
`sudo nvidia-smi -pm ENABLED`

### 4. install nvidia-docker(https://github.com/NVIDIA/nvidia-docker)
```
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-container-toolkit

# For legacy command "nvidia-docker" 
sudo apt-get install -y \
    nvidia-docker2

sudo systemctl restart docker
```