连接到 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