Assume that the driver is installed,
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) # 18.04
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
docker pull nvidia/cuda # this will give error
docker pull nvidia/cuda:11.4.1-devel-ubuntu18.04 # this should be
# testing
docker run --gpus all nvidia/cuda:11.4.1-devel-ubuntu18.04 nvidia-smi
docker pull tensorflow/tensorflow:latest-gpu-py3
docker pull tensorflow/tensorflow:latest-gpu-py3-jupyter
# testing
docker run --gpus all -it --rm tensorflow/tensorflow:latest-gpu-py3 python -c "import tensorflow as tf; print(tf.version); print(tf.test.is_gpu_available()); print(tf.test.is_built_with_cuda())" # should return True
docker pull nvcr.io/nvidia/pytorch:18.04-py3
docker run --gpus all -it --rm nvcr.io/nvidia/pytorch:18.04-py3 python -c "import torch; print(torch.cuda.is_available())"