Created
June 10, 2020 09:44
-
-
Save miraculixx/16c751a4a2c7d3a90582f2ea19cef08e to your computer and use it in GitHub Desktop.
rancher nividia docker 19.03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# this is the rancher docker installation script with nvidia support | |
# apply to NVIDIA GPU nodes only | |
# sources | |
# https://www.tensorflow.org/install/docker | |
# https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#pre-installation-actions | |
# https://github.com/NVIDIA/nvidia-docker/wiki/Frequently-Asked-Questions#how-do-i-install-the-nvidia-driver | |
# https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#ubuntu-installation | |
# https://github.com/NVIDIA/k8s-device-plugin/issues/166 | |
# install docker from default rancher script | |
function install_docker() { | |
curl -L https://releases.rancher.com/install-docker/19.03.sh -o install-docker.sh | |
chmod +x install-docker.sh | |
./install-docker.sh | |
} | |
# install nvidia docker on top | |
function install_nvidia() { | |
# pre-install | |
lspci | grep -i nvidia | |
uname -m && cat /etc/*release | |
apt-get install -y gcc | |
gcc --version | |
sudo apt-get install linux-headers-$(uname -r) | |
# install cuda | |
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin | |
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 | |
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | |
sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /" | |
sudo apt-get update | |
sudo apt-get -y install cuda | |
# install nvidia docker | |
# https://github.com/NVIDIA/nvidia-docker/blob/master/README.md#ubuntu-160418042004-debian-jessiestretchbuster | |
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 | |
# install nvidia device plugin, still required | |
# https://github.com/NVIDIA/k8s-device-plugin/issues/166 | |
# install the old nvidia-container-runtime for k8s | |
curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \ | |
sudo apt-key add - | |
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) | |
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \ | |
sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list | |
sudo apt-get update | |
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit | |
sudo apt-get install -y nvidia-container-runtime | |
cat <<EOF > /etc/docker/daemon.json | |
{ | |
"default-runtime": "nvidia", | |
"runtimes": { | |
"nvidia": { | |
"path": "/usr/bin/nvidia-container-runtime", | |
"runtimeArgs": [] | |
} | |
} | |
} | |
EOF | |
echo "Restarting docker daemon" | |
sudo systemctl restart docker | |
} | |
function check_docker_gpu() { | |
echo "docker: checking with --gpus all flag" | |
docker run --gpus all --rm nvidia/cuda nvidia-smi | |
echo "docker: checking without --gpus all flag" | |
docker run nvidia/cuda:10.2-runtime-ubuntu18.04 nvidia-smi | |
} | |
echo "nvidia-docker: installation starts ***" | |
install_docker | |
install_nvidia | |
check_docker_gpu | |
echo "nvidia-docker: installation ends ***" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment