在 Docker 中安装 Zivid
The instructions for installing Zivid software in a Docker container depend on your operating system and hardware. Follow the instructions that apply to your setup.
先决条件
如果您使用的是英特尔显卡,则主机上应该已经安装了英特尔 GPU 驱动程序。如果没有,请下载并安装 Intel drivers 。
下载以下内容 Dockerfile ,以获得在 Ubuntu 24.04 上使用 Zivid 软件的最小 Docker 镜像。
FROM ubuntu:24.04
RUN apt-get update && apt-get install --assume-yes \
wget \
intel-opencl-icd
RUN wget --quiet \
https://downloads.zivid.com/sdk/releases/2.18.0+1b44dbef-1/u24/amd64/zivid-opencl_2.18.0+1b44dbef-1_amd64.deb \
https://downloads.zivid.com/sdk/releases/2.18.0+1b44dbef-1/u24/amd64/zivid-tools_2.18.0+1b44dbef-1_amd64.deb \
https://downloads.zivid.com/sdk/releases/2.18.0+1b44dbef-1/u24/amd64/zivid-genicam_2.18.0+1b44dbef-1_amd64.deb
RUN apt-get update
RUN apt-get install ./*.deb --assume-yes && rm ./*.deb
导航到放置 Dockerfile 的目录,然后通过运行以下指令来构建和运行容器
sudo docker build -t <image> .
sudo docker run --interactive --tty --device=/dev/dri --network=host <image>
where <image> is your chosen name of the image, e.g. zivid.
You should now be in an interactive session on Ubuntu with Zivid installed.
The --network=host argument lets the container discover cameras on the host network.
首先,如果未安装 GPU 的驱动程序,请在主机上安装 NVIDIA 驱动程序 。然后在主机上安装 NVIDIA Container Toolkit。
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list \
&& \
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
然后配置 Docker 以使用 NVIDIA Container Runtime。
sudo nvidia-ctk runtime configure --runtime=docker
重新启动 Docker daemon。
sudo systemctl restart docker
现在您应该能够通过 Docker 访问您的 NVIDIA GPU。下载以下内容 :downloadDockerfile</../../build/ci/build/documentation/generated_files/dockerfiles/nvidia/ Dockerfile >` ,以获取在 Ubuntu 24.04 上使用 Zivid 软件构建的最小 Docker 镜像。
FROM nvidia/cuda:12.5.1-runtime-ubuntu24.04
RUN apt-get update && apt-get install --assume-yes \
wget
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
RUN wget --quiet \
https://downloads.zivid.com/sdk/releases/2.18.0+1b44dbef-1/u24/amd64/zivid-cuda_2.18.0+1b44dbef-1_amd64.deb \
https://downloads.zivid.com/sdk/releases/2.18.0+1b44dbef-1/u24/amd64/zivid-tools_2.18.0+1b44dbef-1_amd64.deb \
https://downloads.zivid.com/sdk/releases/2.18.0+1b44dbef-1/u24/amd64/zivid-genicam_2.18.0+1b44dbef-1_amd64.deb
RUN apt-get update
RUN apt-get install ./*.deb --assume-yes && rm ./*.deb
导航到放置 Dockerfile 的目录,然后通过运行以下指令来构建和运行容器
sudo docker build -t <image> .
sudo docker run --interactive --tty --device=/dev/dri --gpus=all --network=host <image>
where <image> is your chosen name of the image, e.g. zivid.
You should now be in an interactive session on Ubuntu with Zivid installed.
The --network=host argument lets the container discover cameras on the host network.
To verify that the Zivid SDK works, run the following inside the container.
ZividListCameras
If there are no errors then the Zivid SDK is working within the Docker container.
备注
默认情况下,您只能找到具有静态IP地址 172.28.60.5 的相机。如果您需要连接一个或多个自定义IP地址的相机,请查看 连接到 Docker 中的相机 。
On Windows, Docker Desktop runs Linux containers through the WSL backend.
The Intel path uses the OpenCL compute backend. On WSL, OpenCL is not available to Docker containers, so the OpenCL backend cannot be used on Windows. Use the CUDA backend instead, as shown in the NVIDIA tab. This requires an NVIDIA GPU, so running Zivid in Docker on Windows is not possible with an Intel GPU.
On WSL, the NVIDIA GPU driver exposes CUDA to Docker containers, so the CUDA backend is used.
先决条件
Docker Desktop with the WSL 2 based engine enabled.
An NVIDIA GPU with a recent driver, verified by running
nvidia-smi.
Download the following Dockerfile for a minimal Docker image using Zivid software on Ubuntu 24.04.
FROM nvidia/cuda:12.5.1-runtime-ubuntu24.04
RUN apt-get update && apt-get install --assume-yes \
wget
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
RUN wget --quiet \
https://downloads.zivid.com/sdk/releases/2.18.0+1b44dbef-1/u24/amd64/zivid-cuda_2.18.0+1b44dbef-1_amd64.deb \
https://downloads.zivid.com/sdk/releases/2.18.0+1b44dbef-1/u24/amd64/zivid-tools_2.18.0+1b44dbef-1_amd64.deb \
https://downloads.zivid.com/sdk/releases/2.18.0+1b44dbef-1/u24/amd64/zivid-genicam_2.18.0+1b44dbef-1_amd64.deb
RUN apt-get update
RUN apt-get install ./*.deb --assume-yes && rm ./*.deb
Navigate to the directory where you placed the Dockerfile, and build and run the container from a Windows terminal by running
docker build -t <image> .
docker run --interactive --tty --gpus all <image>
where <image> is your chosen name of the image, e.g. zivid.
The image already targets the CUDA backend, so no further configuration is needed.
To verify that the Zivid SDK works, connect to the camera by its IP address.
Docker Desktop runs containers in the WSL virtual machine, which does not reach cameras on the LAN through mDNS discovery, so ZividListCameras will not find the camera on Windows.
A direct connection by IP address does work.
Create a small program that connects to the camera, replacing 172.28.60.5 with your camera's IP address.
#include <Zivid/Zivid.h>
#include <iostream>
int main()
{
Zivid::Application zivid;
auto camera = zivid.connectCamera(Zivid::CameraAddress{ "172.28.60.5" });
std::cout << "Connected to " << camera.info().serialNumber() << std::endl;
}
Build and run it inside the container. If it prints the camera serial number, the Zivid SDK is working. See 连接到 Docker 中的相机 for more on connecting by IP address or hostname.
备注
A camera can only be connected to from one place at a time. Disconnect the camera in Zivid Studio, or any other application, before connecting from the container. Otherwise the connection times out waiting for the camera to respond.
Version History
SDK |
Changes |
|---|---|
2.18.0 |
Added support for running Zivid in Docker on Windows, through the WSL backend with the CUDA compute backend. |