sudo emerge -av nvidia-container-toolkit
restart docker service:
sudo systemctl restart docker
Create and setup /etc/cdi:
mkdir -p /etc/cdi
nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml
Check if its working:
nvidia-ctk cdi list
Configure docker to use NVIDIA runtime:
sudo nvidia-ctk runtime configure --runtime=docker
Restart docker service again:
sudo systemctl restart docker
Before creating distrobox container, lets just perfrom basic check if nvidia is avaiable in docker:
docker run --rm --device=nvidia.com/gpu=all ubuntu nvidia-smi
If this shows your Nvidia driver and info about your gpu, than it works.
Create distrobox that uses nvidia (fedora 43 as an example):
distrobox create -i quay.io/fedora/fedora:43 -n fbox -H ~/home-fbox --additional-flags "--device=nvidia.com/gpu=all"
Enter the distrobox container, fbox, in this example, and test using nvidia-smi:
sudo nvidia-smi
This should also give info about your nvidia gpu and its driver.
If inside the distrobox container, nvidia is only avaiable for root user, you have to check what group number is nvidia on the host:
stat -c "%g" /dev/nvidia0
This will show a number, e.g. 27. Then in the distrobox container, fbox in this example, you have to edit /etc/group and:
1. add yourself (i.e. normal user) to video group 2. Change video group number to match the one on the host, e.g. 27. For example, /etc/group in fbox
video:x:27:your-user-name