How to install docker and NVIDIA docker in Ubuntu 16.04

Time:2021-7-23

Docker installation

1. Replace the domestic software source, recommend the source of University of science and technology of China, stable and fast (optional)


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. Install the required packages


sudo apt install apt-transport-https ca-certificates software-properties-common curl

3. Add the GPG key and the docker CE software source. Take the docker CE source of University of science and technology of China as an example


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. Update the package cache after adding successfully

sudo apt update

5. Install docker CE

sudo apt install docker-ce

6. Set the boot to start automatically and start docker Ce (it is set and started by default after successful installation, which can be ignored)


sudo systemctl enable docker
sudo systemctl start docker

7. Test run

sudo docker run hello-world

8. Add the current user to the docker user group, and you can run docker without sudo (optional)


sudo groupadd docker
sudo usermod -aG docker $USER

9. Test add user group (optional)

docker run hello-world

NVIDIA docker installation

1. Uninstall NVIDIA docker 1.0 and other GPU containers


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. Add 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. Install NVIDIA docker2


sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd

4. Test and installation


docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi
References

https://docs.docker.com/install/

https://github.com/NVIDIA/nvidia-docker

summary

The above is the course of installing docker and NVIDIA docker in ubuntu16.04 introduced by Xiaobian. I hope it can help you. If you have any questions, please leave me a message and Xiaobian will reply you in time. Thank you very much for your support to developer!
If you think this article is helpful to you, please reprint, please indicate the source, thank you!