You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker容器中访问NI cDAQ设备的驱动安装与挂载问题

如何在Docker容器中通过Python访问NI cDAQ设备?

我尝试在Docker容器中通过Python脚本访问NI cDAQ设备,初始使用的Python脚本如下:

import nidaqmx

task = nidaqmx.Task()
task.do_channels.add_do_chan(lines="cDAQ1Mod1/port0/line0")
task.write(1)

驱动安装失败的尝试

我使用以下Dockerfile安装设备驱动时失败:

FROM ubuntu:latest

ENV DEBIAN_FRONTEND noninteractive

RUN apt update && apt-get install -y \
    apt-utils \
    python3 \
    pip
RUN pip install --no-cache-dir nidaqmx

COPY ni_drivers.deb ./
RUN apt install ./ni_drivers.deb
RUN apt update && apt install -y \
    ni-xnet \
    ni-daqmx \
    ni-serial
RUN dkms autoinstall

COPY hellodaq.py ./
CMD ["python3", "./hellodaq.py"]

构建过程中出现如下报错信息:

Error! Bad return status for module build on kernel: 5.15.0-43-generic (x86_64)
Consult /var/lib/dkms/ni843x/21.5.0f124/build/make.log for more information.
dpkg: error processing package ni-843x-dkms (--configure):
 installed ni-843x-dkms package post-installation script subprocess returned error exit status 10

最终报错:

E: Sub-process /usr/bin/dpkg returned an error code (1)

(由于构建失败无法运行容器,如何查看/var/lib/dkms/ni843x/21.5.0f124/build/make.log文件?)

未安装驱动的容器尝试

因此我尝试在未安装驱动的Docker容器中运行脚本,对应的Dockerfile如下:

FROM ubuntu:latest    

RUN apt update && apt-get install -y \
    python3 \
    pip

RUN pip install --no-cache-dir nidaqmx    
COPY hellodaq.py ./
CMD ["python3", "./hellodaq.py"]

挂载主机驱动的尝试

作为替代方案,我尝试从主机系统挂载设备驱动:

sudo docker run \
--mount type=bind,source=/usr/lib/x86_64-linux-gnu/ni-daqmx,target=/usr/lib/x86_64-linux-gnu/ni-daqmx \
--mount type=bind,source=/usr/share/ni-daqmx,target=/usr/share/ni-daqmx \
hellodaq

但该方案未解决问题,Python脚本仍无法访问设备驱动。

疑问

  • 是否可以挂载已安装的deb包(尤其是设备驱动)?
  • 是否遗漏了步骤,比如在Docker容器中添加驱动到PATH?(是否有必要这么做?)
  • 有没有其他方法可以在Docker容器中访问cDAQ设备?

内容的提问来源于stack exchange,提问作者Benedict H.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 10:21:36