3

I am trying to access a NI cDAQ device from a Python script in a Docker container, using this python script (as a start):

import nidaqmx

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

I have failed to install the device driver using this 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"]

During the build, I get the following message:

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

And ultimately:

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

(whats the best way of reading var/lib/dkms/ni843x/21.5.0f124/build/make.log? Since the build fails I cannot run the container.)

Therefore I tried to run the script in a Docker without the device driver:

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"]

As a replacement, I tried to mount the device driver from the host system:

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

However, this has not resolved the issue, and the python script cannot access the device driver.

Is it even possible to mount installed deb packages, device drivers specifically? Did I forget a step, i.e. adding the device driver to the PATH in the Docker container? (is that a thing?)

Is there some alternative way to do access the cDAQ from a Docker container?

Benedict H.
  • 129
  • 7
  • Why do you think it can not be installed into the docker image? – Klaus D. Aug 05 '22 at 13:03
  • There is a pending idea on the NI idea exchange describing similar problems: https://forums.ni.com/t5/Data-Acquisition-Idea-Exchange/Support-installation-of-nidaqmx-python-in-a-Docker-container/idi-p/3921651 And I've tried installing it, and it fails. I will add some more detail about this in the question. – Benedict H. Aug 05 '22 at 13:07
  • I edited the question to include information about the failed driver installation. – Benedict H. Aug 05 '22 at 13:20
  • 1
    I think you need to provide the `--device` flag with the `dev/*` location of your cdaq to docker since you are trying to access the hardware of the host. These posts will help you - https://stackoverflow.com/questions/24225647/docker-a-way-to-give-access-to-a-host-usb-or-serial-device/30205490#30205490, https://stackoverflow.com/questions/28641128/where-to-install-device-drivers-to-make-docker-recognize-the-device, https://github.com/ni/nidaqmx-python/issues/77#issuecomment-733854614 – viggnah Aug 05 '22 at 13:23
  • 1
    Since it is in a `dkms` folder I guess it is trying to build a kernel module. This should really happen on the host. There should also be some kind of device node created by the kernel module, which has to mounted into the container as noted by @viggnah – Klaus D. Aug 05 '22 at 13:25
  • @viggnah Thank you for the suggestion. This works for Serial, USB and Ethernet devices, but not for NI DAQmx devices. Its functionality is encapsulated by NI software, and can only be controlled by the NI drivers and software libraries. – Benedict H. Aug 08 '22 at 11:21
  • @KlausD. Thank you, that was helpful to understand why it doesn't work. It means its futile to continue trying, as I understand? Is it possible to give a Docker container access to a Kernel module? – Benedict H. Aug 08 '22 at 11:22

0 Answers0