This repository builds a Docker-based development environment for C++ projects that depend on CUDA, cuDNN, TensorRT, OpenCV, and CMake. It is intended for local development on Linux hosts with NVIDIA GPUs.
The repository also vendors related C++ projects in modules/ as Git submodules.
build/Dockerfile: main development imagebuild/Dockerfile.ros2: ROS 2 extension imagedocker-compose.yaml: long-running dev container with GPU access and a bind mount of the workspacemodules/: related C++ libraries and applications
- Linux host
- Docker Engine with Compose support
- NVIDIA driver working on the host
- NVIDIA Container Toolkit
- A TensorRT archive that matches the versions configured in
.env
Check the host driver before building anything:
nvidia-smiClone the repository and initialize submodules:
git clone --recurse-submodules https://github.com/HenrikTrom/Docker-OpenCV-TensorRT-Dev
cd Docker-OpenCV-TensorRT-Dev
git submodule update --init --remote --recursiveReview .env. The main variables you will usually care about are:
UBUNTU_IMAGE_VERSION=24.04
CUDA_VERSION=12.9.2
TENSORRT_VERSION=10.14.1.48
CUDA_ARCH_BIN=8.6
OPENCV_VERSION=4.13.0
UID=1000
GID=1000
TAG1=opencv-trt-dev
TAG2=opencv-trt-ros2-dev
ROS_DISTRO=jazzy
CMAKE_VERSION=3.27.7
CPP_OPTIMIZATIONS="-DNDEBUG -O3 -Wno-deprecated-declarations"Docker will prefer environment variables already present in your shell over values in .env, so avoid exporting conflicting values unless that is intentional.
Place the matching TensorRT archive in:
./build/vision_dependencies/tensorrt/
The install script accepts either the expected .tar.gz archive or the NVIDIA .tar.tar naming used by some downloads.
Build and start the container:
docker compose up -d --buildVerify GPU access inside the container:
docker exec -it "${TAG1}" nvidia-smiThere are two different failure modes worth distinguishing:
-
Host driver failure
nvidia-smifails on the host and inside the container. Fix the host first. -
Container-only GPU dropout
nvidia-smikeeps working on the host but later fails inside a long-running container withFailed to initialize NVML: Unknown Error.
The second case is a known NVIDIA Container Toolkit issue in some Docker/runc/systemd cgroup setups. This repository mitigates it by explicitly mapping the NVIDIA device nodes in docker-compose.yaml.
If a running container loses GPU access, recreate it:
docker compose down
docker compose up -d --buildIf the issue persists, check whether Docker is using Cgroup Driver: systemd:
docker infoNVIDIA documents two stronger mitigations for affected hosts:
- switch Docker to
cgroupfs - use NVIDIA CDI instead of the legacy hook-based
gpus: allpath
- Ubuntu 20.04, CUDA 11.8, TensorRT 8.6.1.6, OpenCV 4.10.0
- Ubuntu 20.04, CUDA 12.3, TensorRT 10.6.1.6, OpenCV 4.10.0
- Ubuntu 24.04, CUDA 12.9, TensorRT 10.14.1.48, OpenCV 4.13.0
- Docker Engine 24+
If you use this repository in academic work, use the GitHub "Cite this repository" entry.