To enable GPU access inside Docker containers, install the NVIDIA Container Toolkit on the Docker host:
π Official installation guide:
https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html
After installation, test that the NVIDIA runtime works by running:
docker run --runtime=nvidia --gpus all --rm -it nvidia/cuda:12.3.1-base-ubuntu20.04 nvidia-smiThis should display GPU usage information from nvidia-smi.
If your Docker host is itself an LXC container, you might encounter the following error:
stderr: Auto-detected mode as 'legacy'
nvidia-container-cli: mount error: failed to add device rules: unable to find any existing device filters attached to the cgroup: bpf_prog_query(BPF_CGROUP_DEVICE) failed: operation not permitted: unknown.Edit the config file:
sudo nano /etc/nvidia-container-runtime/config.tomlSet the following option:
no-cgroups = trueThen restart Docker:
sudo systemctl restart docker