前言
需要 nvdia driver
安装好,请参考 Ubuntu Nvidia driver驱动安装及卸载
docker 安装
配置 apt
阿里云的镜像源
sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
配置
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \
&& curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
安装 docker
和 nvidia-docker2
sudo apt-get update
apt install docker-ce docker-ce-cli
sudo apt-get install -y nvidia-docker2
如果你只用docker,这一步不用操作。
但如果你是 k8s
环境 需要配置 cgroupdriver
改使用 systemd
# Set up cgroupdriver
cat > /etc/docker/daemon.json << EOF
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
设置 docker
开机自启,重启加载 docker
配置
systemctl enable docker
systemctl restart docker
测试docker是否占用gpu
在 docker
中使用 gpu
,必须在创建容器时打开 --gpus
参数,并保证 docker
的版本在 19.03
以上。
运行一个基本的CUDA容器来测试是否配置完成
sudo docker run --rm --runtime=nvidia --gpus all nvidia/cuda:12.0.1-runtime-ubuntu22.04 nvidia-smi
输出如下所示,就代表你的容器以及支持GPU:
Thu Apr 25 08:53:22 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.154.05 Driver Version: 535.154.05 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 Tesla T4 Off | 00000000:00:05.0 Off | 0 |
| N/A 39C P0 25W / 70W | 105MiB / 15360MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 3812267 C /usr/local/bin/python 100MiB |
+---------------------------------------------------------------------------------------+
标签:Nvidia,sudo,apt,ce,nvidia,GPU,docker
From: https://www.cnblogs.com/niuben/p/18155185