A Docker-based C++ development environment with OpenCV (latest) and CUDA 13.0 support on Ubuntu 24.04. Includes GPU-accelerated computer vision, X11 display forwarding, and a simple build system via make.
- Base image:
nvidia/cuda:13.0.2-cudnn-devel-ubuntu24.04 - OpenCV: Built from source with full CUDA/cuDNN acceleration
- CUDA Compute: Configured for
sm_89(RTX 40-series); easy to adjust - C++23 compilation via
g++ - X11 forwarding for GUI windows (
cv::imshow, etc.) - Volume mount: host project directory mounted at
/appinside the container - FFmpeg / GStreamer / V4L2 codec support included
| Requirement | Notes |
|---|---|
| NVIDIA GPU | Compute capability ≥ 8.9 (or adjust CUDA_ARCH_BIN in Dockerfile) |
| NVIDIA driver | Compatible with CUDA 13.0 |
| Docker Engine | 20.10+ |
| NVIDIA Container Toolkit | Enables --gpus all |
| 16 GB free disk space | OpenCV source build is large |
| 8 GB RAM | Recommended for parallel compilation |
.
├── Dockerfile # Multi-layer image: CUDA base → deps → OpenCV build
├── docker-build.sh # Build the Docker image
├── docker-run.sh # Run container with GPU, X11, and volume mount
├── docker-clean.sh # Remove the built Docker image
├── Makefile # Compile & run the test program inside the container
├── img/ # Screenshots
│ └── sshot.jpg # Screenshot of the running application
├── src/ # Source code folder
│ └── test_opencv_cuda.cpp # Sample program: draws text on an image, rotates using CUDA and shows on screen
└── build/ # Compilation output (created by make)
└── test_opencv_cuda # Compiled binary
⚠️ This step compiles OpenCV from source and takes 20–60 minutes depending on your hardware.
./docker-build.shThis builds and tags the Docker image as opencv-cuda-13.02-dev.
./docker-run.shThis drops you into an interactive shell inside the container with:
- GPU access (
--gpus all) - Your project directory mounted at
/app - X11 display forwarding (for
cv::imshow)
Inside the container:
make # compiles test_opencv_cuda.cpp → build/test_opencv_cuda
make run # runs build/test_opencv_cuda (creates build/foo.jpg)
make clean # removes build artifactsThe sample program:
- Creates a 640×480 white image with a blue border and centered green "Hello World" text (CPU)
- Uploads the image to the GPU (
cv::cuda::GpuMat) - Rotates it 90° counter-clockwise using
cv::cuda::rotate()— this confirms CUDA is working - Downloads the result back to CPU
- Saves
build/foo_rotated.jpg(rotated) - Displays finale image on host via X11
To remove the Docker image when no longer needed:
./docker-clean.sh| Target | Description |
|---|---|
make / make all |
Compile test_opencv_cuda.cpp into build/test_opencv_cuda |
make run |
Run the compiled binary |
make clean |
Delete everything in build/ |
Compilation uses C++23 (-std=c++23 -O2) and links against OpenCV 4 (via pkg-config) and CUDA runtime.
