1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
| # !/bin/bash
start_message(){
cat << ENTER
============= 脚本安装工具 =============
Version: 0.1
Date: 20201125
Author:小刘同学
Usage: 安装英伟达tkl工具链
eg:使用该脚本之间,最好已经换了默认安装源,
如果下载速度过慢,可以中断改脚本,逐行执行
============= 脚本安装工具 =============
ENTER
}
finish_message(){
cat << FINISH
============= 脚本安装工具 =============
脚本已经安装完成
拉取镜像,看环境是否配置成功
sudo docker run --runtime=nvidia --rm nvidia/cuda:10.2-base nvidia-smi
如果有输出,则安装成功
============= 脚本安装工具 =============
FINISH
}
do_docker(){
sudo add-apt-repository ppa:graphics-drivers/ppa #更新安装源
sudo apt-get install nvidia-driver-440
apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | 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
apt-get install -y docker-ce docker-ce-cli containerd.io
}
do_nvidia(){
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
# 安装nvidia-docker2软件包并重新加载docker守护程序配置
sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd
}
read -p "安装英伟达的docker镜像 yes|no: " input
if [ $input == "yes" ] || [ $input == "y" ]
then
echo "2秒开始安装"
start_message
sleep 2
do_docker
echo "安装docker完成"
docker --version
do_nvidia
echo "安装英伟达docker完成"
finish_message
elif [ $input == "no" ] || [ $input == "n" ]
then
exit 0
else
echo "输入错误,请重试"
exit
fi
|