Skip to content

How To: Use Basler USB Cameras in a Docker Container#

The following article assumes that you are familiar with Docker installation and Docker commands.

Here is the configuration we are using:

  • Host OS: Ubuntu 20.04 and pylon 6.2
  • Guest OS: Ubuntu 20.04 and pylon 6.2

Proceed as follows:

  1. Create a directory of your choice on your host system, e.g., /home/user/dockerImage.
  2. Save the following text as a file named Dockerfile in the above directory:
    FROM ubuntu:20.04
    LABEL maintainer=""
    LABEL version="0.1"
    LABEL description="This is custom Docker Image"
    RUN apt-get update && apt-get install build-essential  locales-all joe vim -y
    RUN apt-get install dialog apt-utils  usbutils -y
    ARG PUID=1000
    ARG PGID=1000
    RUN groupadd -g ${PGID} ${USERNAME} \
                && useradd -u ${PUID} -g ${USERNAME} -d /home/${USERNAME} ${USERNAME} \
                && mkdir /home/${USERNAME} \
                && chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}
    ENV DIR=/home/imcome
    RUN echo $DIR
    RUN mkdir -p ${DIR} && \
              chmod +r ${DIR}
    COPY *.deb ${DIR}
    VOLUME [${DIR}]
    RUN dpkg -i ${DIR}/pylon*.deb
    CMD "/bin/bash"
  3. Download and save a pylon Debian package into this directory.
  4. Open a terminal, head to the directory and execute the following command to generate a Docker image based on public Ubuntu 20.04 image:

    sudo docker build -t pylon

    This command also installs pylon in Docker image.

  5. Run fresh built image using the following command:

    sudo docker run -ti -v '/dev/bus/usb':'/dev/bus/usb' --privileged -e DISPLAY=$DISPLAY -v '/tmp/.X11-unix':'/tmp/.X11-unix' pylon

You will now see all Basler USB cameras connected to the host system in the Docker container as well.

You can then carry on your work. Run lsusb or build the grab sample and run it.

Back to Knowledge Articles