This document showcases the required steps to setup the proper environment for running Docker containers.
To allow effective use of the Docker container, we can utilise dedicated graphics to improve performance of GUI applications.
If you are running on Ubuntu. Install NVIDIA drivers from the PPA GPU drivers repository.
- Add the PPA repository
sudo add-apt-repository ppa:graphics-drivers/ppa
- Identify the GPU model and available drivers
ubuntu-drivers devices
The output should be similar to this
Devices Output
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001F91sv00001043sd0000106Fbc03sc00i00
vendor : NVIDIA Corporation
model : TU117M [GeForce GTX 1650 Mobile / Max-Q]
driver : nvidia-driver-515 - third-party non-free
driver : nvidia-driver-535-server - distro non-free
driver : nvidia-driver-450-server - distro non-free
driver : nvidia-driver-545-open - third-party non-free
driver : nvidia-driver-460 - third-party non-free
driver : nvidia-driver-465 - third-party non-free
driver : nvidia-driver-418-server - distro non-free
driver : nvidia-driver-525 - third-party non-free
driver : nvidia-driver-545 - third-party non-free
driver : nvidia-driver-520 - third-party non-free
driver : nvidia-driver-535-open - distro non-free
driver : nvidia-driver-535-server-open - distro non-free
driver : nvidia-driver-495 - third-party non-free
driver : nvidia-driver-450 - third-party non-free
driver : nvidia-driver-455 - third-party non-free
driver : nvidia-driver-535 - third-party non-free
driver : nvidia-driver-550 - third-party non-free recommended # <-- Find the recommended driver
driver : nvidia-driver-470-server - distro non-free
driver : nvidia-driver-550-open - third-party non-free
driver : nvidia-driver-470 - third-party non-free
driver : nvidia-driver-510 - third-party non-free
driver : xserver-xorg-video-nouveau - distro free builtin
- Install the NVIDIA driver
sudo apt install nvidia-driver-550
- Reboot the system
sudo reboot
Tip
If you are running on WSL2
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin && sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600 && wget https://developer.download.nvidia.com/compute/cuda/12.4.1/local_installers/cuda-repo-wsl-ubuntu-12-4-local_12.4.1-1_amd64.deb && sudo dpkg -i cuda-repo-wsl-ubuntu-12-4-local_12.4.1-1_amd64.deb && sudo cp /var/cuda-repo-wsl-ubuntu-12-4-local/cuda-*-keyring.gpg usr/share/keyrings/ && sudo apt-get update && sudo apt-get -y install cuda-toolkit-12-4
- Prepare the repositories and sources
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
- Update the packages
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
Tip
If you have not setup Docker yet, follow the following Installation options.
Configuring the Docker
sudo nvidia-ctk runtime configure --runtime=docker
Restart the Docker Daemon
sudo systemctl restart docker
nvidia-ctk runtime configure --runtime=docker --config=$HOME/.config/docker/daemon.json
Restart the Docker daemon
systemctl --user restart docker
Perform some configuration
sudo nvidia-ctk config --set nvidia-container-cli.no-cgroups --in-place
To test if a container is running with accellerated GPU from the host system, we can run a sample workload to test compatibility.
sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
In the docker container, the output should be similar to this
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.15 Driver Version: 550.54.15 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce GTX 1650 Off | 00000000:01:00.0 On | N/A |
| N/A 37C P8 3W / 50W | 710MiB / 4096MiB | 34% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
+-----------------------------------------------------------------------------------------+