1. Starting with Docker
2. Dockerfile
3. Management in Docker
4. Docker image size reduction
5. Docker GPU passthrough
6. Docker inside Visual Studio Code
7. Docker and ROS
8. Docker Compose
9. Docker with the Jetson platform
In this tutorial we use a NVIDIA graphics card for GPU acceleration inside Docker containers. There is a possibility that this tutorial is going to be extended to other manufactures, but for now it is only NVIDIA based.
Note: You should already have the NVIDIA CUDA toolkit installed and should be able to run the command
nvidia-smi
, which displays your gpu driver version and CUDA version.
First we need to setup the GPG key from the package repository for the NVIDIA Container Toolkit
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& 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/$distribution/libnvidia-container.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
Note: Check the lines that are printed and if it has the correct ubuntu version that is installed, there is a small change that it is wrong. The
apt-get update
won't work if it added the list for the wrong distribution. Usesudo nano /etc/apt/sources.list.d/nvidia-container-toolkit.list
to change it to the correct distribution.
Now the package listing can be updated and the NVIDIA Container Toolkit can be installed,
sudo apt-get update
sudo apt-get install -y nvidia-docker2
Restart Docker to complete the installation
sudo systemctl restart docker
Now you should be able to run and build containers with CUDA available. This can be tested using an example CUDA base container,
docker run --rm --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi
That is all to get GPU acceleration inside containers, for more information on docker see below for the next step.