openEuler-22.03(LTS-SP3)安装Nvidia-Docker
可参考官网给出的文档进行安装:https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html#id1
💡 进行 Docker 配置之前,请确保您的主机上的 NVIDIA 驱动程序正常工作,能够成功运行nvidia-smi并看到您的 GPU
名称、驱动程序版本和 CUDA 版本
安装NVIDIA Container Toolkit
检查系统是否安装了Nvidia-Docker
docker info | grep -i nvidia #看到nvidia相关的输出,表明Docker已经支持GPU
Runtimes: io.containerd.runc.v2 nvidia runc #类似这样的输出,如果没有输出安装下面的配置进行安装,前提需安装Docker!
设置存储库和 GPG密钥
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.repo | sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo
更新包列表后安装 nvidia-container-toolkit 包
yum clean expire-cache
yum install -y nvidia-container-toolkit
配置Docker守护进程识别Nvidia容器运行时
nvidia-ctk runtime configure --runtime=docker
重启Docker
systemctl restart docker
验证测试
运行基本 CUDA 容器来测试工作设置
docker run --rm --runtime=nvidia --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi
Thu Aug 29 13:06:14 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.90.07 Driver Version: 550.90.07 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| 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:81:00.0 Off | 0 |
| N/A 33C P8 11W / 70W | 102MiB / 15360MiB | 4% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
| 1 Tesla T4 Off | 00000000:83:00.0 Off | 0 |
| N/A 35C P8 9W / 70W | 5MiB / 15360MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
+-----------------------------------------------------------------------------------------+
也可以加入 -L 参数,只显示显卡
docker run --rm --runtime=nvidia --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi -L
GPU 0: Tesla T4 (UUID: GPU-0cefb662-23de-8e91-5c38-da184fdd8611)
GPU 1: Tesla T4 (UUID: GPU-60561464-ad84-6860-982c-9ffa4953393e)
部署Unity程序
- 制作Unity镜像
FROM nvidia/cuda:11.0-base
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
USER root
RUN apt-get update && apt-get install -y \
libx11-6 \
libxrandr2 \
libxinerama1 \
libxcursor1 \
libglu1-mesa \
libxcomposite1 \
libgl1-mesa-glx \
libxi6 \
libxtst6 \
vulkan-utils \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir /home/unity
COPY . /home/unity
RUN chmod 777 -R /home/unity/
WORKDIR /home/unity
CMD ["./linux_1.x86_64"]
- 构建镜像
docker build -t unity:v1 .
- XDG_RUNTIME_DIR
export XDG_RUNTIME_DIR=/tmp/runtime-root
mkdir -p /tmp/runtime-root
chmod 0700 /tmp/runtime-root
#确保主机和容器内的 DISPLAY 变量设置正确,通常为 :0 或其他显示编号。例如:
export DISPLAY=:0
docker run --name unity -itd --gpus all -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=compute,utility,graphics -v /tmp/.X11-unix:/tmp/.X11-unix:rw -e DISPLAY=$DISPLAY -e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR -it unity:v1