Skip to content

Instantly share code, notes, and snippets.

@hshimamoto
Created January 13, 2022 10:10
Show Gist options
  • Save hshimamoto/6d7eed31a683fcf3740aaa34bb926d4a to your computer and use it in GitHub Desktop.
Save hshimamoto/6d7eed31a683fcf3740aaa34bb926d4a to your computer and use it in GitHub Desktop.
Scripts for nvidia-docker
#!/bin/bash
cd $(dirname $0)
source /etc/os-release
# install cuda drivers
function install_cuda_drivers()
{
# add key and repository
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
sudo apt-get update
sudo apt-get -y install cuda-drivers
}
function install_docker()
{
# get.docker.com
curl https://get.docker.com | sh
sudo usermod -aG docker $USER
}
function install_nvidia_docker2()
{
curl -sL https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -sL https://nvidia.github.io/nvidia-docker/$ID$VERSION_ID/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update
sudo apt-get -y install nvidia-docker2
sudo systemctl restart docker
}
nvidia-smi
if [ $? -ne 0 ]; then
# no nvidia-smi
install_cuda_drivers
echo "try again"
exit 0
fi
docker ps
if [ $? -ne 0 ]; then
# no docker
install_docker
install_nvidia_docker2
echo "try again"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment