连接到 Docker 中的相机
本文介绍了如何在 Docker 中使用自定义 IP 地址连接到一台或多台相机。
备注
在继续之前,请确保您已在主机上配置了 网络配置 。
备注
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.
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.
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.
sudo docker run --interactive --tty --device=/dev/dri --network=host <image>
sudo docker run --interactive --tty --gpus=all --network=host <image>
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.
Zivid SDK 可以通过使用 Cameras.yml 来搜索特定的 IP 地址,而不是使用 mDNS。查看 Cameras.yml以及如何限制可发现的相机 以了解有关其工作原理的更多信息。将以下内容添加到您的 Dockerfile 以发现具有非默认 IP 的相机。
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