2023年ubuntu安装GPU版本docker详细步骤

1 安装显卡驱动,版本应与内核版本相同。 从仓库一条命令安装所有驱动,不成功用自带的软件与更新安装。

sudo ubuntu-drivers autoinstall

2 安装docker engine ,才发现现在有桌面版,应该很好用,但是没用过,还是选择docker engine

,更新太快了,docker已经18.04起了,官网安装地址Install Docker Engine on Ubuntu | Docker Documentation

2023年ubuntu安装GPU版本docker详细步骤_第1张图片

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

3 安装测试,成功与否在此一举,在这之前建议换自己阿里云的国内加速链接。

 sudo docker run hello-world

4 开始安装docker的gpu版本,添加源,官方地址GitHub - NVIDIA/nvidia-container-toolkit: Build and run containers leveraging NVIDIA GPUs

GitHub - NVIDIA/nvidia-docker: Build and run Docker containers leveraging NVIDIA GPUs

Installation Guide — NVIDIA Cloud Native Technologies documentation

curl https://get.docker.com | sh \
  && sudo systemctl --now enable docker



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


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/experimental/$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-get update


sudo apt-get install -y nvidia-container-toolkit


sudo nvidia-ctk runtime configure --runtime=docker


sudo systemctl restart docker



 下面的可以省略。

sudo mkdir -p /etc/systemd/system/docker.service.d

sudo tee /etc/systemd/system/docker.service.d/override.conf <

5 可省略

sudo cat /etc/group | grep docker
sudo groupadd docker 
sudo gpasswd -a ${USER} docker 
sudo chmod a+rw /var/run/docker.sock
sudo systemctl restart docker 

6 改镜像

sudo gedit /etc/docker/daemon.json

改成
{
  "registry-mirrors": ["https://yxzrazem.mirror.aliyuncs.com"],
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    }
}
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo docker info

7 测试,有可能下载不了,换其他的镜像即可。

sudo docker run --rm --runtime=nvidia --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi

8 附加一张成功的图片

 

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