Opencv on l4t-base container

I am trying to create a Dockerfile on jetson with l4t-base and create a new image with opencv but when i try to build an image I encounter a linking problem and I can only create a docker when I change the command from RUN to CMD, but then it builds every time, which is a problem.

I am trying to build it using this:
RUN curl -L -o
RUN curl -L -o
RUN unzip && unzip
RUN cd opencv-4.1.0/ && mkdir release && cd release/ && cmake -D WITH_CUDA=ON
-D OPENCV_EXTRA_MODULES_PATH=…/…/opencv_contrib-4.1.0/modules
-D BUILD_opencv_python2=OFF
-D BUILD_opencv_python3=ON


Any luck getting linking to work in such a way that result of the step was cached by docker? I’m running into a similar issue.


  • Harris

Here is a script to build OpenCV in docker, along with a sample Dockerfile. You should be able to just replace the FROM line in the Dockerfile with a deepstream base image (edit: see post below for the correct base image).

If you’re still on JetPack 4.3 you can use a tag here here
like mdegans/tegra-opencv:jp-r32.3.1-cv-4.3.0 (and apt install deepstream-4.0

Otherwise latest always will target the latest JetPack and latest OpenCV.


I’m trying to use you suggested method of incorporating opencv into the deepstream image (on an xavier agx, l4t R32.4.3). I’ve therefore changed the Dockerfile to contain:


### build argumements ###
# change these here or with --build-arg FOO="BAR" at build time
# note: 8 jobs will fail on Nano. Try 1 instead.
# required for apt-get -y to work properly:
ARG DEBIAN_FRONTEND=noninteractive

WORKDIR /usr/local/src/build_opencv


RUN /bin/bash

However I receive the following error when I run

sudo docker build --tag deepstream_opencv:1.0


+ mv /etc/apt/sources.list.d/nvidia-l4t-apt-source.list /etc/apt/    
mv: cannot stat '/etc/apt/sources.list.d/nvidia-l4t-apt-source.list': No such file or directory

It seems that the deepstream image does not have this file. Commenting out the lines where it moves the file from and back to /etc/apt/sources.list.d then leads to the following:

E: Unable to locate package cuda-compiler-10-2
E: Unable to locate package cuda-minimal-build-10-2
E: Unable to locate package cuda-libraries-dev-10-2
E: Unable to locate package libcudnn8-dev

Please help me!

Many thanks

The issue is that official Nvidia images do not currently have Nvidia’s apt sources enabled and I didn’t think about that when writing the above post… Here is a patched deepstream image and dockerfile you can use to build your own from a deepstream-l4t base:

Let me know if …


… works for you or not (i may have to adjust the script). I just update it for 4.4GA but haven’t tested building on top of this DeepStream base image.

Thanks ever so much - looks like it’s working so far. I’ll update when complete.

Yes I can confirm that it works, as long as I use opencv master rather than 4.3 tag as indicated here: Jetpack 4.4 Broke one of my programs