1. 检查自己的显卡类型,同时在宿主机上安装显卡驱动
一般选择推荐的 proprietary,tested
2. 配置lxd的容器并添加GPU设备
3. 在容器中运行相同驱动版本
在nvidia官网上下载驱动
sh NVIDIA-Linux-x86_64-520.61.05.run --no-kernel-module
4. 在容器中配置docker 版本19以上
针对docker中使用GPU需要安装和运行一下脚本
nano nvidia.sh
sudo curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \
sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
sudo curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \
sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update
sh nvidia.sh
apt install nvidia-container-runtime
验证
which nvidia-container-runtime
响应是:
/usr/bin/nvidia-container-runtime
5. 配置docker中env
docker run --gpus=all -itd -p 5555:5555 -p 41451:41451 -e DISPLAY=:1001 -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=graphics,compat32,utility,display -e LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/usr/lib/i386-linux-gnu:/usr/local/nvidia/lib:/usr/local/nvidia/lib64 -e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -e DEBIAN_FRONTEND=noninteractive -e GLIBC_TUNABLES=glibc.rtld.dynamic_sort=2 -v /home/ubuntu/dev:/airsim_dev -v /tmp/.X11-unix:/tmp/.X11-unix --privileged=true --network=uav-default --ip 172.18.0.2 --name ue ue:0.1 /bin/bash
环境变量很关键
-e DISPLAY=:1001 -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=graphics,compat32,utility,display -e LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/usr/lib/i386-linux-gnu:/usr/local/nvidia/lib:/usr/local/nvidia/lib64 -e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -e DEBIAN_FRONTEND=noninteractive -e GLIBC_TUNABLES=glibc.rtld.dynamic_sort=2
7. 在容器中就能使用nvidia
标签:bin,container,lxd,usr,nvidia,GPU,runtime,local,20.04 From: https://www.cnblogs.com/youran-he/p/17465248.html