在Ubuntu上安装Docker并使得Docker支持GPU

在Ubuntu上安装Docker并使得Docker支持GPU

Install docker

sudo apt update
sudo apt upgrade -y
sudo apt install  -y ca-certificates  curl  gnupg  lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt upgrade -y
sudo apt install docker-ce docker-ce-cli containerd.io -y
sudo docker run --rm  hello-world

Install Docker Engine on Ubuntu

Manage docker as a non-root user

sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

Configure mirror accelerator

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://3ydrafq1.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

the url of aliyun mirror accelerator can be repalced by others.

Configure docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Support GPU

sudo docker run --help | grep -i gpus | wc -L
# run the second instruction only if the output of the first instruction is equal to 0
distribution=\$(. /etc/os-release;echo \$ID\$VERSION_ID) && curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list 
sudo apt update
sudo apt install -y nvidia-docker2
sudo systemctl restart docker
sudo docker run -it --rm --gpus all ubuntu nvidia-smi

Setting up NVIDIA Container Toolkit

你可能感兴趣的:(docker,ubuntu)