Docker でカメラに接続する

To connect to a camera in Docker without mDNS discovery, either connect by IP address or hostname, expose the host network to the container, or list the camera's IP in a Cameras.yml file.

注釈

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

注釈

These instructions are independent of the compute backend. See Docker に Zivid をインストールする 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.

Connect by IP address or hostname

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 キャプチャチュートリアル. This is the simplest option when you are connecting to a specific camera at a known address.

Host network

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.

Intel
sudo docker run --interactive --tty --device=/dev/dri --network=host <image>
NVIDIA
sudo docker run --interactive --tty --gpus=all --network=host <image>
Jetson
sudo docker run --interactive --tty --runtime=nvidia --gpus=all --network=host <image>

ここで <image> は、コンテナの起動元となる Docker イメージです。これにより、すべてのホスト ネットワーク インターフェイスがコンテナに公開されることに注意してください。

注釈

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.

Cameras.yml

Zivid SDK can search for specific IP addresses instead of using mDNS by using a file Cameras.yml. Check out Restrict Discoverable Cameras with Cameras.yml 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

Host フィールドを変更して特定の IP アドレスを持つカメラを検出するか、別の NetworkCamera を追加します。変更を反映させるには、Docker イメージを再度ビルドしてください。

注釈

These workarounds restore mDNS discovery in the container. If you know the camera's address, your application can instead connect to it directly with connect by IP address or hostname, which does not rely on mDNS and needs no Cameras.yml file.

以下を実行して、接続されているすべてのカメラを Docker コンテナ内で検出できることを確認します。

ZividListCameras