Fix GPU setup: check and install nvidia-container-toolkit

dupfinder-setup.sh now verifies nvidia-container-toolkit is present
when a GPU is detected. If missing, prints install instructions and
offers to install it automatically (adds NVIDIA repo, installs toolkit,
configures Docker runtime, restarts Docker).

Without this toolkit Docker silently falls back to CPU even when a
GPU is present and the compose file has the device reservation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
tocmo
2026-04-05 01:57:51 -04:00
parent a6748de6e0
commit f37bd76fed

View File

@@ -53,12 +53,45 @@ if ! docker compose version &>/dev/null; then
fi
ok "docker compose V2 available"
# ── Check NVIDIA GPU ──────────────────────────────────────────────────────────
# ── Check NVIDIA GPU + container toolkit ─────────────────────────────────────
info "Checking GPU..."
if command -v nvidia-smi &>/dev/null && nvidia-smi &>/dev/null; then
GPU_NAME=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1)
ok "NVIDIA GPU detected: $GPU_NAME"
GPU_AVAILABLE=true
# nvidia-container-toolkit is required for Docker GPU passthrough
if ! command -v nvidia-ctk &>/dev/null && ! dpkg -l nvidia-container-toolkit &>/dev/null 2>&1; then
echo ""
echo " nvidia-container-toolkit is not installed."
echo " Without it Docker cannot pass the GPU to the container."
echo " Install with:"
echo ""
echo " curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg"
echo " 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"
echo " sudo apt update && sudo apt install -y nvidia-container-toolkit"
echo " sudo nvidia-ctk runtime configure --runtime=docker"
echo " sudo systemctl restart docker"
echo ""
read -rp " Install nvidia-container-toolkit now? (Y/n): " INST_CTK
if [[ "$INST_CTK" != "n" && "$INST_CTK" != "N" ]]; then
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey \
| 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' \
| tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
apt update -qq && apt install -y nvidia-container-toolkit
nvidia-ctk runtime configure --runtime=docker
systemctl restart docker
ok "nvidia-container-toolkit installed and Docker restarted"
else
echo " Skipping — GPU will not be available in Docker. You can re-run setup later."
GPU_AVAILABLE=false
fi
else
ok "nvidia-container-toolkit is present"
fi
[[ "$GPU_AVAILABLE" != "false" ]] && GPU_AVAILABLE=true
else
echo " No NVIDIA GPU detected — will use CPU for perceptual hashing"
GPU_AVAILABLE=false