docker支持GPU安装和配置
本实践将在 Ubuntu 22.04.3LTS 系统上进行安装测试
参考资料 : nvidia-container-toolkit
目前安装版本
nvidia-container-toolkit -version
NVIDIA Container Runtime Hook version 1.14.3
commit: 53b24618a542025b108239fe602e66e912b7d6e2
安装操作脚本
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 apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
cat /etc/docker/daemon.json
{
"default-runtime": "nvidia",
"bip": "192.168.88.1/24",
"registry-mirrors": [
"https://docker.nju.edu.cn"
],
"runtimes": {
"nvidia": {
"args": [],
"path": "nvidia-container-runtime"
}
}
}
sudo systemctl restart docker
sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
vim /usr/local/bin/nvidia-docker
nvidia-docker 脚本
新版本nvidia-docker命令行已经移除
nvidia-docker参考 : nvidia-docker
nvidia-docker
```bash! /bin/bash
Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
NV_DOCKER=${NV_DOCKER:-"docker"}
DOCKER_ARGS=()
NV_DOCKER_ARGS=()
while [ $# -gt 0 ]; do
arg=$1
shift
DOCKER_ARGS+=("$arg")
case $arg in
run|create)
NV_DOCKER_ARGS+=("--runtime=nvidia")
if [ ! -z "${NV_GPU}" ]; then
NV_DOCKER_ARGS+=(-e NVIDIA_VISIBLE_DEVICES="${NV_GPU// /,}")
fi
break
;;
version)
printf "NVIDIA Docker: @VERSION@\n"
break
;;
--)
break
;;
esac
done
if [ ! -z $NV_DEBUG ]; then
set -x
fi
exec $NV_DOCKER "${DOCKER_ARGS[@]}" "${NV_DOCKER_ARGS[@]}" "$@"
```