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 a few changes, so we strongly recommend going through that tutorial first to refresh your memory before continuing here.
The Dockerfile and build script below come from a community example and were written for older ZED SDK, Ubuntu, and CUDA versions (the compatibility check only allows Ubuntu 18.04 / 20.04 and CUDA 10 / 11). Use them to understand the workflow, then adapt the versions to your needs. The latest ZED SDK is v5.4.0, which uses CUDA 12.8 / 13.0 on Ubuntu 22.04 / 24.04. For officially maintained Dockerfiles and ready-to-use images, see the zed-docker GitHub repository and the StereoLabs DockerHub repository.
A generic Dockerfile skeleton is provided to assemble an image, along with a build script, build-opencv-desktop-image.sh, that specifies the build arguments. build-opencv-desktop-image.sh lets you configure the build arguments and then build the Docker image, allowing you to customize your container.
Dockerfile Overview
The full Dockerfile contains many instructions, explained in detail below. You can adapt this file to your requirements.
Below is an analysis of the main parts that make up the Dockerfile.
Specify the parent image
First, specify the base ZED SDK Docker image you want to build from. These images come with the ZED SDK pre-installed and let you use the ZED camera with SDK applications.
There are many Docker images available with different Ubuntu release years and SDK and CUDA versions. We therefore choose a specific ZED SDK Docker image as the parent image by configuring the build arguments.
The Ubuntu release year and the SDK and CUDA versions are passed as arguments during the build stage, which keeps the Dockerfile modular. Setting these arguments to the version of your choice is covered in a later section.
Based on the arguments set in the build script, a specific base image is imported. For example, if the build arguments in build-opencv-desktop-image.sh are set to the values below:
then the base image will be stereolabs/zed:3.7-gl-devel-cuda11.4-ubuntu20.04.
Note that this base image already includes OpenGL support for display. If you do not need it, follow the section below to build an image without display support.
You can also browse the StereoLabs DockerHub repository, which lists all the official ZED SDK Docker images.
Install dependencies
Once you have specified the parent image, you can choose which OpenCV version to install. Be sure 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 explained below.
Method 1: Install OpenCV from source
This step downloads the OpenCV source files for the chosen version and builds them.
Make sure you remove this section if you choose the second method.
Method 2: Install OpenCV from the Ubuntu repository
Alternatively, you can simply install OpenCV from the Ubuntu repository.
This is a much simpler way to install OpenCV and produces a lighter image, but building OpenCV from source gives you the latest available version, more flexibility, and complete control over the build options.
Choose the method that best fits your needs.
Build Script Overview
As mentioned above, the Docker image can be built for various versions. The build-opencv-desktop-image.sh script lets you configure the versions passed during the build and then creates the image with the docker build command.
The script is detailed below.
Configure the arguments
Specify the Ubuntu release year and the ZED SDK, CUDA, and OpenCV versions. The default values set in the script are shown below; edit them to the versions you want. These arguments are later passed as --build-arg during the build.
Check version compatibility
This part of the script validates the arguments you entered above and checks compatibility between the different versions. If an entry is invalid, the build is aborted.
Docker build
The part of the script below assigns a default tag to the image based on the chosen arguments and runs the build.
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 versions, and run the script to build the Docker image.
That’s it! You can now change versions and create your own Docker containers just by editing 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 a display window is only possible in containers with OpenGL support.
By leaving out OpenGL, you can make the Docker images much lighter and remove the need for all the dependencies required for display support. There are a few ways to achieve this.
Choose a parent Docker image without OpenGL support by changing the parent image tag (drop the gl- prefix), as follows:
You can read more about the image-specific tags on the StereoLabs DockerHub page.
- In your application, the output image window can be saved instead of displayed. Below is a snippet from the
zed-opencvsample that uses theENABLE_DISPLAYflag to either display the image or save it as a video.
Refer to the zed-opencv GitHub repository for the complete code.

