Creating a Docker Image for your ZED Application
This is the recommended workflow for creating your own Docker image for your application:
- Write a Dockerfile for your application.
- Build the image with
docker buildcommand. - Host your Docker image on a registry.
- Pull and run the image on the target machine.
Write the Dockerfile
Docker builds images automatically by reading the instructions from a Dockerfile. It is a text file that contains all commands needed to build a given image.
In the following example, we will build and run the Hello ZED tutorial application in a container.
First let’s prepare the host with the code:
Open a text editor and create a new Dockerfile with the following content:
We provide some extra arguments to CMake to ensure that CMake and GCC can find all the required CUDA libraries. We also tell the compiler to allow linking even if there are undefined symbols from libraries such as nvcuvid that are not yet available. These will be available at runtime by using the NVIDIA® container toolkit.
For more information on writing dockerfiles, check Dockerfile reference documentation.
Build your Docker Image
Now that you have created a Dockerfile, it’s time to build your image using the docker build command.
Tips: On NVIDIA® Jetson™, we recommend building your Jetson™ Docker Container on x86 host, and running it on the target NVIDIA® Jetson™ device to avoid long compilation time on boards such as NVIDIA® Jetson™ Nano.
Test the Image
Let’s start the container based on the new image we created using the docker run command.
On NVIDIA® Jetson™ or older Docker versions, use these arguments:
If you use ZED X, you need a few more shared volumes.
You should now see the output of the terminal.
When running a Docker image on an NVIDIA® Jetson™ device, please ensure that the L4T (Linux for Tegra) version of your host system matches the L4T version of the container you are using.
Volumes
When running a Docker image for ZED Cameras a few volumes should be shared with the host.
- [optional]
/usr/local/zed/resources:/usr/local/zed/resources: if you plan to use the AI module of the ZED SDK (Object Detection, Skeleton Tracking, NEURAL depth) we suggest binding mounting a folder to avoid downloading and optimizing the AI models each time the Docker image is restarted. The first time you use the AI model inside the Docker image, it will be downloaded and optimized in the local bound-mounted folder, and stored there for the next runs. - [required]
/dev:/dev: required to share the video devices - For GMSL2 cameras (ZED X):
- [required]
/tmp:/tmp - [required]
/var/nvidia/nvcam/settings/:/var/nvidia/nvcam/settings/ - [required]
/etc/systemd/system/zed_x_daemon.service:/etc/systemd/system/zed_x_daemon.service
- [required]
Optimize your Image Size
Docker images can get very large and become a problem when pulling over the network or pushing on devices with limited storage (such as NVIDIA® Jetson™ Nano). Here is a few pieces of advice to keep your image size small:
-
Minimize the number of
RUNcommands. Each command adds a layer to the image, so consolidating the number ofRUNcan reduce the number of layers in the final image. Note that layers are designed to be reusable, and will not be pushed or pulled if they didn’t change. -
Use
--no-install-recommendswhen installing packages withapt-get installto disable the installation of optional packages and save disk space. -
Remove tarballs or other archive files that were copied during the installation. Each layer is added on top of the others, so files that were not removed in a given
RUNstep will be present in the final image even if they are removed in a laterRUNstep. -
Similarly, clean package lists that are downloaded with
apt-get updateby removing/var/lib/apt/lists/*in the sameRUNstep. -
Create separate images for development and production. Production images should not include all of the libraries and dependencies pulled in by the build.
-
Use multi-stage builds (see Docker docs) and push only your
prodimage.
Host your Docker Image
Now that you have created your image, you need to share it on a registry so it can be downloaded and run on any destination machine. A registry is a stateless, server-side application that stores and lets you distribute Docker images.
Use Docker Hub Registry
By default, Docker provides an official free-to-use registry, DockerHub, where you can push and pull your images. For example at StereoLabs, the ZED SDK Docker images are built automatically by a public Gitlab CI job and pushed to StereoLabs DockerHub repository.
There are situations where you will not want your image to be publicly available. In this case, you need to create your own private Docker Registry. You can get private repos from Docker, or from many other third-party providers.
Use Local Registry Server
For local development, if your host and target machines are on the same network, you can set up a local registry server and push your images there.
For more information on deploying your own registry server, please refer to Docker docs.
Save and Load Images as Files
Lastly it is also possible to export and load your Docker image as a file.
To export a Docker image simply use :
On the destination machine, simply load the Docker image using :

