How to Install ZED SDK with Docker on Linux

Setting Up Docker

Install Docker on your local host machine.

# Automatic setup script
curl -sSL https://get.docker.com/ | sh

# Run docker to make sure installation worked
sudo docker run hello-world

To run docker commands without sudo, create a Unix group called docker and add users to it. Note that the docker group grants privileges equivalent to the root user. For more information, see Docker docs.

Nvidia Docker

Install NVIDIA Docker support using the commands below. This lets you build and run GPU accelerated Docker containers.

# Add the package repositories
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list

sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
# Add the package repositories
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo

sudo yum install -y nvidia-container-toolkit
sudo systemctl restart docker

Make sure you have installed the NVIDIA driver for your graphics card before installing nvidia-container-toolkit.

Nvidia Jetson

For NVIDIA Jetson, skip the step above and follow the Docker install guide for Jetson.

Download a ZED SDK Docker Image

To build and run an application using the ZED SDK, you need to pull a ZED SDK Docker image first. The official ZED SDK Docker images are located in Stereolabs DockerHub repository. The releases are tagged using ZED SDK, CUDA and Ubuntu versions, along with optional support for OpenGL or ROS.

For example, the following downloads these ZED SDK images to your machine:

docker pull stereolabs/zed:3.0-runtime-cuda10.2-ubuntu18.04   # runtime release 3.0
docker pull stereolabs/zed:3.0-devel-gl-cuda10.2-ubuntu18.04  # development release 3.0 with OpenGL support
docker pull stereolabs/zed:2.8-devel-cuda10.0-ubuntu16.04     # development release 2.8

Start a Docker Container

To run a Docker container using a ZED SDK image, use the following command:

docker run --gpus all -it --privileged stereolabs/zed:3.0-runtime-cuda9.0-ubuntu18.04

The --gpus all command adds all available GPUs to the container, and --privileged grants permission to the container to access the camera connected on USB.

Congratulations, the ZED SDK is now available in your container!

Run ZED Explorer Tool

To verify our installation, we are going to run the ZED Explorer tool. By default, a Docker container can only be used to run command-line applications. If we want to add a display window, we need to add OpenGL support to the container.

docker pull stereolabs/zed:3.0-devel-gl-cuda10.2-ubuntu18.04  # pull ZED SDK devel release with OpenGL support
xhost +si:localuser:root  # allow containers to communicate with X server 
docker run -it --runtime nvidia --privileged -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix stereolabs/zed:3.0-devel-gl-cuda10.2-ubuntu18.04
  • --runtime nvidia will use the NVIDIA container runtime.
  • -v /tmp/.X11-unix:/tmp/.X11-unix is required for the container to access the display.
  • -e DISPLAY makes your DISPLAY environment variable available in the container.

Now you can run any OpenGL application in the container. Let’s run ZED Explorer:

/usr/local/zed/tools/ZED_Explorer

You should now be looking at the Explorer GUI application running on your display from a Docker container!

Run a Sample Application

In this example, we will run a simple Depth Sensing sample application available in the ZED SDK sample folder.

apt update && apt install cmake -y
cp -r /usr/local/zed/samples/depth\ sensing/ /tmp/depth-sensing
cd /tmp/depth-sensing ; mkdir build ; cd build
cmake .. && make
./ZED_Depth_Sensing

Next Steps

Read the next section to learn how to create your own Docker image for your application.