Ubuntu16.04安装Docker、nvidia-docker
Docker安装
1.更换国内软件源,推荐中国科技大学的源,稳定速度快(可选)
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
sudo apt update
2.安装需要的包
sudo apt install apt-transport-https ca-certificates software-properties-common curl
3.添加 GPG 密钥,并添加 Docker-ce 软件源,这里还是以中国科技大学的 Docker-ce 源为例
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable"
4.添加成功后更新软件包缓存
sudo apt update
5.安装 Docker-ce
sudo apt install docker-ce
6.设置开机自启动并启动 Docker-ce(安装成功后默认已设置并启动,可忽略)
sudo systemctl enable docker
sudo systemctl start docker
7.测试运行
sudo docker run hello-world
8.添加当前用户到 docker 用户组,可以不用 sudo 运行 docker(可选)
sudo groupadd docker
sudo usermod -aG docker $USER
9.测试添加用户组(可选)
docker run hello-world
Nvidia-docker安装
1. 卸载 nvidia-docker 1.0 及其他GPU容器
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
2. 添加package repositories
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
3. 安装 nvidia-docker2
sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd
4. 测试安装
docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi
References
https://docs.docker.com/install/
https://github.com/NVIDIA/nvidia-docker