ZED camera does not open in docker container as a non-root user

Description

Using the Python API inside a docker container with a NON-root user, I get the following output when trying to open the camera object:

CAMERA FAILED TO SETUP

When the same attempt is performed with root, the output is SUCCESS.

Steps to reproduce

  1. Create a docker image from the official stereolabs zed image, and add a user with sudo priviledges. Then add permissions for the zed folder and python libraries.

The following Dockerfile is suggested.

FROM stereolabs/zed:3.8-devel-cuda11.7-ubuntu20.04
ARG USERNAME=user
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
RUN chmod -R 777 /usr/local/zed/
RUN chmod -R 777 /usr/local/lib/python3.8/dist-packages/
WORKDIR /home/user
USER user

Save in a file called Dockerfile and build with:

docker build -f Dockerfile -t zed:test .
  1. Then open the console in the docker container with GPU capabilities:

In host PC:

xhost +si:localuser:root

Then:

docker run --gpus all -it --privileged zed:test
  1. Execute the following script in python3:
import pyzed.sl as sl
zed = sl.Camera()
init_params = sl.InitParameters()
err = zed.open(init_params)
print(err)

Expected result:

SUCCESS

Actual result:

CAMERA FAILED TO SETUP

Setup

  • Camera model: ZED2i
  • OS: Ubuntu 22.04
  • CPU: AMD64
  • GPU: GeForce RTX 3080
  • CUDA Version 11.7
1 Like

I am currently facing the same issue. Let’s keep in touch

1 Like

Hi @ArciAndres and @AleSantopa
Welcome to the Stereolabs community.

What is the command that you are using to start the Docker container?

Hi @Myzhar . Thanks for the reply.
I put it in the post. I am using this:

docker run --gpus all -it --privileged zed:test

Or do you refer to another command?

1 Like

Can you try adding this:
--runtime nvidia -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix

Thanks for the reply.

I just tried it adding the suggested tags, and the result is the same (CAMERA FAILED TO SETUP).

If I do it as root (with sudo su), it works. Unfortunately, I cannot deploy my whole system as root, hence I need to do it with a user.

1 Like

@ArciAndres did you install the Stereolabs udev rules on the host device?

1 Like

You can use this script to install the udev rules without installing the ZED SDK:

Thank you for the script.
I did run the lines of that code, but at the end the trick was to add the user to the video group, which was not present.

Insert in the docker file (before changing user):

RUN usermod -a -G video user
2 Likes

Hi @ArciAndres
thank you for the feedback and the solution :+1:

Hey, thanks for the provided information. I have an additional issue. I applied the provided solution and the container runs smoothly on my developer computer. Unfortunately if I run it on our deployment computer I get the following error:
[zed_wrapper-1] Error opening camera: CAMERA NOT DETECTED
[zed_wrapper-1] Please verify the camera connection
[zed_wrapper-1] ZED activation interrupted by user.

I use the following setup:

  • stereolabs/zed:4.0-devel-cuda11.8-ubuntu20.04
  • ros2 foxy
  • I run the computer with:

docker run -it --rm --name=“zed2i_driver” --user $(id -u ${USER}):$(id -g ${USER}) -v /dev:/dev -v /run/udev/data:/run/udev/data:ro -v /usr/local/zed/resources/:/usr/local/zed/resources/ --gpus all --privileged --net=host -e ROS_DOMAIN_ID=0 container_name

I can see the camera in the container if check it like this

lsusb | grep Microchip
Bus 001 Device 004: ID 0424:2512 Microchip Technology, Inc. (formerly SMSC) USB 2.0 Hub

If I run the same container as root it works great.