Skip to content

Instantly share code, notes, and snippets.

@nathantsoi
Last active December 6, 2024 15:00
Show Gist options
  • Save nathantsoi/e668e83f8cadfa0b87b67d18cc965bd3 to your computer and use it in GitHub Desktop.
Save nathantsoi/e668e83f8cadfa0b87b67d18cc965bd3 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
sudo apt-get install -y docker-ce
# remove old nvidia-docker
docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
sudo apt-get purge -y nvidia-docker
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 docker2
apt-get install -y nvidia-docker2
pkill -SIGHUP dockerd
# install yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install -y yarn
# configure nvidia for build-time gpu access
sudo apt-get install -y nvidia-container-runtime
cat << EOF | sudo tee /etc/docker/daemon.json
{
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime",
"runtimeArgs": []
}
},
"default-runtime": "nvidia"
}
EOF
sudo systemctl restart docker
# Test nvidia-smi with the latest official CUDA image
echo "DONE!"
echo "Add your user to the docker group:"
echo ' sudo usermod -aG docker $USER'
echo " Login again and test with:"
echo " docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi"
@nathantsoi
Copy link
Author

nathantsoi commented Sep 24, 2020

one line install (sudo apt install curl first, if not already installed)

curl -L https://gist.githubusercontent.com/nathantsoi/e668e83f8cadfa0b87b67d18cc965bd3/raw/setup_docker.sh | sudo bash

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