当前位置:   article > 正文

ubuntu22.04 安装 docker cuda

ubuntu22.04 安装 docker cuda

ubuntu22.04 安装 docker cuda

系统初始化

sudo apt update
sudo apt install vim git proxychains openssh-server curl build-essential python3 -y
  • 1
  • 2

安装cuda12.2.0

wget https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run
chmod +x cuda_12.2.0_535.54.03_linux.run 
sudo sh cuda_12.2.0_535.54.03_linux.run
# 根据提示添加环境变量在文件末尾
gedit ~/.bashrc 
export PATH=$PATH:/usr/local/cuda-12.2/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-12.2/lib64
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

安装cudnn

nvcc -V
# 需要注册账号登录
# 下载:https://developer.nvidia.com/downloads/compute/cudnn/secure/8.9.7/local_installers/12.x/cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz/
tar -xvf cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz 
sudo cp cudnn-linux-x86_64-8.9.7.29_cuda12-archive/include/cudnn*.hh /usr/local/cuda/include
sudo cp cudnn-linux-x86_64-8.9.7.29_cuda12-archive/include/cudnn*.h /usr/local/cuda/include
sudo cp -P cudnn-linux-x86_64-8.9.7.29_cuda12-archive/lib/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

安装miniconda3

./Miniconda3-py310_24.1.2-0-Linux-x86_64.sh

# 修改conda镜像源
gedit ~/.condarc
# https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/
source ~/.bashrc 
# 修改python镜像源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
conda clean -i
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

安装docker

# 里面下载下面的文件
# 网址:https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/
sudo dpkg -i containerd.io_1.6.31-1_amd64.deb 
sudo dpkg -i docker-ce-cli_26.1.0-1~ubuntu.20.04~focal_amd64.deb 
sudo dpkg -i docker-ce_26.1.0-1~ubuntu.20.04~focal_amd64.deb 
sudo dpkg -i docker-compose-plugin_2.26.1-1~ubuntu.20.04~focal_amd64.deb 
sudo dpkg -i docker-buildx-plugin_0.14.0-1~ubuntu.20.04~focal_amd64.deb 
# 修改docker镜像源
# 下面的地址需要自己申请:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

安装docker-cuda库

sudo 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/stable/deb/nvidia-container-toolkit.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 sed -i -e '/experimental/ s/^#//g' /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo apt-get install -y nvidia-docker2
sudo systemctl restart docker
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

测试docker-cuda是否正常安装

sudo docker run --rm --gpus all nvidia/cuda:12.2.0-base-ubuntu22.04 nvidia-smi
  • 1

下载yolo最新的库

sudo docker pull ultralytics/ultralytics

# Run with all GPUs
sudo docker run -it --ipc=host --gpus all ultralytics/ultralytics
# 具体网址:`https://docs.ultralytics.com/zh/guides/docker-quickstart/`
  • 1
  • 2
  • 3
  • 4
  • 5
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/570406
推荐阅读
相关标签
  

闽ICP备14008679号