Unable to create a docker to run CUDA on JETSON AGX ORIN for opencv

I tried to run the container for CUDA L4T according to the docs but stumbled upon this error.

docker run -it --rm --net=host --runtime nvidia -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix nvcr.io/nvidia/l4t-cuda:12.2.12-devel    

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: nvidia-container-runtime did not terminate successfully: exit status 1: time="2024-07-16T15:31:08+02:00" level=error msg="failed to create NVIDIA Container Runtime: failed to construct OCI spec modifier: requirements not met: unsatisfied condition: cuda>=12.2 (cuda=11.4)"
: unknown.

Tried pulling an older image and I get manifest unknown:

opencv-nvidia sudo docker run -it --rm --net=host --runtime nvidia -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix nvcr.io/nvidia/l4t-cuda:11.4-devel 

Unable to find image 'nvcr.io/nvidia/l4t-cuda:11.4-devel' locally
docker: Error response from daemon: manifest for nvcr.io/nvidia/l4t-cuda:11.4-devel not found: manifest unknown: manifest unknown.
See 'docker run --help'.
➜  opencv-nvidia docker pull ros:noetic-pytorch-l4t-r34.1.1 
Error response from daemon: manifest for ros:noetic-pytorch-l4t-r34.1.1 not found: manifest unknown: manifest unknown

Preferably I would like to not update my version of CUDA and ideally I want to build opencv from source with CUDA support with this dockerfile :

# Use NVIDIA CUDA base image with Ubuntu 20.04
FROM looking_for_this

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV OPENCV_VERSION="4.6.0"
ENV WORKSPACE_DIR="/workspace"

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    cmake \
    git \
    libgtk2.0-dev \
    pkg-config \
    libavcodec-dev \
    libavformat-dev \
    libswscale-dev \
    libgstreamer1.0-dev \
    libgstreamer-plugins-base1.0-dev \
    gstreamer1.0-plugins-base \
    gstreamer1.0-plugins-good \
    gstreamer1.0-plugins-bad \
    gstreamer1.0-plugins-ugly \
    gstreamer1.0-libav \
    gstreamer1.0-doc \
    gstreamer1.0-tools \
    python3.8-dev \
    python-dev \
    python-numpy \
    python3-numpy \
    libtbb2 \
    libtbb-dev \
    libjpeg-dev \
    libpng-dev \
    libtiff-dev \
    libdc1394-22-dev \
    libv4l-dev \
    v4l-utils \
    qv4l2 \
    curl \
    unzip

# Remove default OpenCV if required (uncomment to enable this step)
# RUN apt -y purge '*libopencv*'

# Create workspace directory
RUN mkdir ${WORKSPACE_DIR}

# Download OpenCV and OpenCV contrib sources
WORKDIR ${WORKSPACE_DIR}
RUN curl -L https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip -o opencv-${OPENCV_VERSION}.zip && \
    curl -L https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip -o opencv_contrib-${OPENCV_VERSION}.zip && \
    unzip opencv-${OPENCV_VERSION}.zip && \
    unzip opencv_contrib-${OPENCV_VERSION}.zip && \
    rm opencv-${OPENCV_VERSION}.zip opencv_contrib-${OPENCV_VERSION}.zip

# Build and install OpenCV
WORKDIR ${WORKSPACE_DIR}/opencv-${OPENCV_VERSION}
RUN mkdir release && cd release && \
    cmake -D WITH_CUDA=ON \
          -D WITH_CUDNN=ON \
          -D CUDA_ARCH_BIN="7.2,8.7" \
          -D CUDA_ARCH_PTX="" \
          -D OPENCV_GENERATE_PKGCONFIG=ON \
          -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \
          -D WITH_GSTREAMER=ON \
          -D WITH_LIBV4L=ON \
          -D BUILD_opencv_python3=ON \
          -D BUILD_TESTS=OFF \
          -D BUILD_PERF_TESTS=OFF \
          -D BUILD_EXAMPLES=OFF \
          -D CMAKE_BUILD_TYPE=RELEASE \
          -D CMAKE_INSTALL_PREFIX=/usr/local .. && \
    make -j$(nproc) && \
    make install

# Update library path
RUN echo 'export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH' >> /etc/bash.bashrc && \
    echo 'export PYTHONPATH=/usr/local/lib/python3.8/site-packages/:$PYTHONPATH' >> /etc/bash.bashrc

# Set the working directory
WORKDIR /

# Clean up
RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/*

COPY test.py /root/test.py
# Print success message
CMD ["tail", "-f", "/dev/null"]

I managed to build and run the docker but it seems I get stuck on this :
opencv-nvidia docker run -it --rm --net=host --runtime=nvidia -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix opencv-cuda-gstreamer

==========
== CUDA ==

CUDA Version 11.4.19

Container image Copyright (c) 2016-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.

This container image and its contents are governed by the NVIDIA Deep Learning Container License.
By pulling and using the container, you accept the terms and conditions of this license:

A copy of this license is made available in this container at /NGC-DL-CONTAINER-LICENSE for your convenience.

After that I can type any command and nothing happens. Cannot exit or ctrl-c aswell I have to stop the docker container with another terminal.

However when I use this command for the official image it works :
opencv-nvidia docker run -it --rm --net=host --runtime=nvidia -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix nvcr.io/nvidia/l4t-cuda:11.4.19-devel
Any idea why my Dockerfile is not working ?

# Use NVIDIA CUDA base image with Ubuntu 20.04
FROM  nvcr.io/nvidia/l4t-cuda:11.4.19-devel

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV OPENCV_VERSION="4.6.0"
ENV WORKSPACE_DIR="/workspace"

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    cmake \
    git \
    libgtk2.0-dev \
    pkg-config \
    libavcodec-dev \
    libavformat-dev \
    libswscale-dev \
    libgstreamer1.0-dev \
    libgstreamer-plugins-base1.0-dev \
    gstreamer1.0-plugins-base \
    gstreamer1.0-plugins-good \
    gstreamer1.0-plugins-bad \
    gstreamer1.0-plugins-ugly \
    gstreamer1.0-libav \
    gstreamer1.0-doc \
    gstreamer1.0-tools \
    python3.8-dev \
    python-dev \
    python-numpy \
    python3-numpy \
    libtbb2 \
    libtbb-dev \
    libjpeg-dev \
    libpng-dev \
    libtiff-dev \
    libdc1394-22-dev \
    libv4l-dev \
    v4l-utils \
    qv4l2 \
    curl \
    unzip

# Remove default OpenCV if required (uncomment to enable this step)
# RUN apt -y purge '*libopencv*'

# Create workspace directory
RUN mkdir ${WORKSPACE_DIR}

# Download OpenCV and OpenCV contrib sources
WORKDIR ${WORKSPACE_DIR}
RUN curl -L https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip -o opencv-${OPENCV_VERSION}.zip && \
    curl -L https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip -o opencv_contrib-${OPENCV_VERSION}.zip && \
    unzip opencv-${OPENCV_VERSION}.zip && \
    unzip opencv_contrib-${OPENCV_VERSION}.zip && \
    rm opencv-${OPENCV_VERSION}.zip opencv_contrib-${OPENCV_VERSION}.zip

# Build and install OpenCV
WORKDIR ${WORKSPACE_DIR}/opencv-${OPENCV_VERSION}
RUN mkdir release && cd release && \
    cmake -D WITH_CUDA=ON \
          -D WITH_CUDNN=ON \
          -D CUDA_ARCH_BIN="7.2,8.7" \
          -D CUDA_ARCH_PTX="" \
          -D OPENCV_GENERATE_PKGCONFIG=ON \
          -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \
          -D WITH_GSTREAMER=ON \
          -D WITH_LIBV4L=ON \
          -D BUILD_opencv_python3=ON \
          -D BUILD_TESTS=OFF \
          -D BUILD_PERF_TESTS=OFF \
          -D BUILD_EXAMPLES=OFF \
          -D CMAKE_BUILD_TYPE=RELEASE \
          -D CMAKE_INSTALL_PREFIX=/usr/local .. && \
    make -j$(nproc) && \
    make install

# Update library path
RUN echo 'export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH' >> /etc/bash.bashrc && \
    echo 'export PYTHONPATH=/usr/local/lib/python3.8/site-packages/:$PYTHONPATH' >> /etc/bash.bashrc

# Set the working directory
WORKDIR /

# Clean up
RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/*

COPY test.py /root/test.py
# Print success message
CMD ["python3", "/root/test.py"]

I found using these images is simpler and efficient :

Only problems might be with ending up with oversized images. Or if you need to install different dependencies, running into versions conflict.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.