Create Docker images for ZED and OpenCV
We have already seen how to create a docker image. In this section, we follow the same recommended workflow with slight changes, so we highly recommend you go through that tutorial to refresh your memory before continuing here.
A generic Dockerfile skeleton is made available to assemble an image and a build script build-opencv-desktop-image.sh that specifies build arguments. build-opencv-desktop-image.sh lets you configure build arguments and then build the Docker image, thereby enabling the customization of your Docker container.
Dockerfile Overview
The full Dockerfile contains many instructions, which are explained in detail later. This file can be altered based on your requirements.
Below is the analysis of the main parts that compose the Dockerfile.
Specify the parent image
First, specify a base ZED SDK docker image from which you want to build the new image. These images come with ZED SDK pre-installed and let you use the ZED camera with SDK applications.
There are multiple Docker images available with different Ubuntu release years, SDK and CUDA versions. Hence, we first choose a specific ZED SDK Docker image as a parent image by configuring the arguments.
The Ubuntu release year, SDK and CUDA versions are passed as arguments during the build stage, making it modular. Assigning these arguments to the version of your choice is discussed in a later section.
Based on the arguments specified in the build script, a specific base image will be imported. For example, if the build arguments in build-opencv-ubuntu-image.sh are set to the values shown below:
Then the base image will be stereolabs/zed:3.7-gl-devel-cuda11.4-ubuntu20.04
Note that the base image is chosen so that it already includes OpenGL support for display. If you do not want it, you can follow the section below to build an image without display support.
Meanwhile, you can also explore the StereoLabs DockerHub repository that contains official ZED SDK Docker images.
Install dependencies
Once you have specified the parent image, you can decide which OpenCV version to install. Be careful to check version availability and compatibility.
This part of the Dockerfile installs all the OpenCV dependencies.
In the next stage, you install OpenCV. This can be done in two ways, both of which are explained below.
Method 1: Install OpenCV from the source
This section downloads the OpenCV source files of the chosen version and builds it.
Make sure you remove this section if you choose to use the 2nd method.
Method 2: Install OpenCV using the Ubuntu repository
Alternatively, you can simply install OpenCV from the Ubuntu repository.
Although this is a much simpler and easier way to install OpenCV that makes your image lighter, building OpenCV from source gives you the latest available version, flexibility and complete control over the build options.
Choose the method that is appropriate for you.
Build Script Overview
As mentioned above, the Docker images can be customized to various available versions, and the build-opencv-ubuntu-image.sh script lets you configure the versions that are passed during the build, and also creates the Docker image using the docker build command.
The script is detailed in this section below.
Configure the arguments
Specify the Ubuntu release year, ZED SDK, CUDA and OpenCV versions. Here you can see the default values set in the script; you should edit them to the version you want. These arguments are later passed as --build-arg during the build.
Check for the version compatibility
This section of the script checks the arguments you entered in the above section and examines compatibility between the different versions. In case of an invalid entry, it exits the build.
Docker build
The part of the script below assigns a default tag to the Docker image to be created based on the chosen arguments, and builds the Docker container.
Create your Docker Image with OpenCV
Now that you are familiar with the Dockerfile and build-opencv-desktop-image.sh, it’s time to create your image.
Download the files from this link, edit the arguments to your desired version, and simply run the script to create the Docker image.
That’s it! You can now change versions and create your own Docker containers just by manipulating the arguments. Go ahead and test your images, then host them as described in this tutorial.
Docker Image without display support
A display window is an integral part of most OpenCV applications. However, Docker is mainly intended to run command-line applications, and adding a display window is possible only in containers with OpenGL support.
By leaving out OpenGL, we can make the Docker images much lighter, and it also removes the need for all the dependencies required to include display support. Below are a few ways to achieve this.
Choose a parent Docker image without OpenGL support, which can be done simply by changing the parent image tag as follows:
You can read more about image-specific tags on StereoLabs’ DockerHub page.
- In the applications, the output image window can be saved instead of displayed. Below is the code snippet from the
zed-opencvsample that uses the ENABLE_DISPLAY flag to either display the image or save it as a video.
Please refer to zed-opencv GitHub repository for the complete code.

