Skip to content

Instantly share code, notes, and snippets.

@m1k1o
Last active March 29, 2021 19:41
Show Gist options
  • Save m1k1o/07ad1cedb52baaa770cceca99c1e9bd6 to your computer and use it in GitHub Desktop.
Save m1k1o/07ad1cedb52baaa770cceca99c1e9bd6 to your computer and use it in GitHub Desktop.
Install Nvidia for Docker on Ubuntu

Install Nvidia CUDA and use it in Docker

1. Download

Should be something like this:

wget https://developer.download.nvidia.com/compute/cuda/11.2.2/local_installers/cuda_11.2.2_460.32.03_linux.runsudo
sh cuda_11.2.2_460.32.03_linux.run

Get actual link from: https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=2004&target_type=runfilelocal

2. Disable nouveau

Create a file at /etc/modprobe.d/blacklist-nouveau.conf with the following contents:

blacklist nouveau
options nouveau modeset=0

Regenerate the kernel initramfs:

sudo update-initramfs -u

https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#runfile-nouveau-ubuntu

3. Install driver

chmod +x cuda_11.2.2_460.32.03_linux.run
./cuda_11.2.2_460.32.03_linux.run --silent --driver

4. Install nvidia-docker2

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
sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi

https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#setting-up-nvidia-container-toolkit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment