Connecting to camera(s) in Docker

This page describes how you can connect to one or multiple cameras with custom IP addresses in Docker.

Note

Make sure you have configured your Network Configuration on the host machine before continuing.

Note

These instructions are independent of the compute backend. See Install Zivid in Docker for the OpenCL and CUDA backend options and which one to use for your host.

Docker uses the bridge network driver by default, which does not allow multicast traffic. This means multicast DNS (mDNS) network discovery is unavailable, and only cameras with default IP 172.28.60.5 can be discovered without further configuration. There are three ways to work around this.

If you know the IP address or hostname of the camera, you can connect to it directly without relying on mDNS discovery. Pass a CameraAddress to connectCamera, as described in Capture Tutorial. This is the simplest option when you are connecting to a specific camera at a known address.

A simple solution is to expose the host network to the Docker container. This can be done by enabling --network=host when running the Docker container, like

sudo docker run --interactive --tty --device=/dev/dri --network=host <image>

where <image> is the Docker image you are launching the container from. Note that this will expose all host network interfaces to the container.

Note

This works on native Linux, where the host network reaches the camera directly. On Windows, Docker Desktop runs containers in the WSL virtual machine. There, --network=host exposes that virtual machine’s network, not the Windows host network, so mDNS discovery does not find the camera. The camera is still reachable by IP address, so on Windows connect by IP address or hostname instead.

Zivid SDK can search for specific IP addresses instead of using mDNS by using a file Cameras.yml. Check out Cameras.yml and how to restrict discoverable cameras to read more about how this works. Add the following to your Dockerfile to discover cameras with non-default IPs.

ENV ZIVID_CONFIG=/root/.config/Zivid/API/Cameras.yml
RUN mkdir --p $(dirname $ZIVID_CONFIG)
RUN echo "__version__: 1"                   >> $ZIVID_CONFIG
RUN echo "Cameras:"                         >> $ZIVID_CONFIG
RUN echo "    NetworkCameras:"              >> $ZIVID_CONFIG
RUN echo "        - NetworkCamera:"         >> $ZIVID_CONFIG
RUN echo "            Host: 172.28.60.5"    >> $ZIVID_CONFIG
RUN echo "        - NetworkCamera:"         >> $ZIVID_CONFIG
RUN echo "            Host: 172.28.60.6"    >> $ZIVID_CONFIG
RUN echo "        - NetworkCamera:"         >> $ZIVID_CONFIG
RUN echo "            Host: 172.28.60.7"    >> $ZIVID_CONFIG

Change the Host field to discover the camera with your specific IP address, or add another NetworkCamera. Build the Docker image again for the changes to take place.

Verify that you can discover all connected cameras in the Docker container by running

ZividListCameras