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

**URL:** <https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259>\
**Category:** Docker\
**Tags:** python\
**Created:** [March 16, 2023, 11:13am UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259 "2023-03-16T11:13:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArciAndres](https://community.stereolabs.com/user_avatar/community.stereolabs.com/arciandres/32/1098_2.png) [@ArciAndres](https://community.stereolabs.com/u/ArciAndres)\
**Post date:** [March 16, 2023, 11:13am UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/1 "2023-03-16T11:13:59Z")

</div>

## 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:

```auto
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](https://www.stereolabs.com/) zed image, and add a user with sudo priviledges. Then add permissions for the zed folder and python libraries.

The following Dockerfile is suggested.

```auto
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:

```auto
docker build -f Dockerfile -t zed:test .

```

1. Then open the console in the docker container with GPU capabilities:

In host PC:

```auto
xhost +si:localuser:root

```

Then:

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

```

1. Execute the following script in `python3`:

```auto
import pyzed.sl as sl
zed = sl.Camera()
init_params = sl.InitParameters()
err = zed.open(init_params)
print(err)

```

### Expected result:

```auto
SUCCESS

```

### Actual result:

```auto
CAMERA FAILED TO SETUP

```

## Setup

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

---

<div class="post-metadata">

**Author:** ![AleSantopa](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@AleSantopa](https://community.stereolabs.com/u/AleSantopa)\
**Post date:** [March 16, 2023, 11:30am UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/2 "2023-03-16T11:30:29Z")

</div>

> [@ArciAndres](#):
>
> `:`

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

---

<div class="post-metadata">

**Author:** ![Myzhar](https://community.stereolabs.com/user_avatar/community.stereolabs.com/myzhar/32/11_2.png) [@Myzhar](https://community.stereolabs.com/u/Myzhar)\
**Post date:** [March 16, 2023, 1:07pm UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/3 "2023-03-16T13:07:50Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![ArciAndres](https://community.stereolabs.com/user_avatar/community.stereolabs.com/arciandres/32/1098_2.png) [@ArciAndres](https://community.stereolabs.com/u/ArciAndres)\
**Post date:** [March 16, 2023, 1:34pm UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/4 "2023-03-16T13:34:18Z")

</div>

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

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

```

Or do you refer to another command?

---

<div class="post-metadata">

**Author:** ![Myzhar](https://community.stereolabs.com/user_avatar/community.stereolabs.com/myzhar/32/11_2.png) [@Myzhar](https://community.stereolabs.com/u/Myzhar)\
**Post date:** [March 16, 2023, 2:27pm UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/5 "2023-03-16T14:27:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ArciAndres](https://community.stereolabs.com/user_avatar/community.stereolabs.com/arciandres/32/1098_2.png) [@ArciAndres](https://community.stereolabs.com/u/ArciAndres)\
**Post date:** [March 16, 2023, 2:45pm UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/6 "2023-03-16T14:45:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Myzhar](https://community.stereolabs.com/user_avatar/community.stereolabs.com/myzhar/32/11_2.png) [@Myzhar](https://community.stereolabs.com/u/Myzhar)\
**Post date:** [March 16, 2023, 3:29pm UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/7 "2023-03-16T15:29:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Myzhar](https://community.stereolabs.com/user_avatar/community.stereolabs.com/myzhar/32/11_2.png) [@Myzhar](https://community.stereolabs.com/u/Myzhar)\
**Post date:** [March 16, 2023, 3:39pm UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/8 "2023-03-16T15:39:55Z")

</div>

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

> <https://gist.github.com/adujardin/2d5ce8f000fc6a7bd40bee2709749ff8>

---

<div class="post-metadata">

**Author:** ![ArciAndres](https://community.stereolabs.com/user_avatar/community.stereolabs.com/arciandres/32/1098_2.png) [@ArciAndres](https://community.stereolabs.com/u/ArciAndres)\
**Post date:** [March 16, 2023, 8:30pm UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/9 "2023-03-16T20:30:01Z")

</div>

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):

```auto
RUN usermod -a -G video user

```

---

<div class="post-metadata">

**Author:** ![Myzhar](https://community.stereolabs.com/user_avatar/community.stereolabs.com/myzhar/32/11_2.png) [@Myzhar](https://community.stereolabs.com/u/Myzhar)\
**Post date:** [March 17, 2023, 8:05am UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/10 "2023-03-17T08:05:50Z")

</div>

Hi @ArciAndres  
thank you for the feedback and the solution 👍

---

<div class="post-metadata">

**Author:** ![Jeremy](https://community.stereolabs.com/user_avatar/community.stereolabs.com/jeremy/32/2608_2.png) [@Jeremy](https://community.stereolabs.com/u/Jeremy)\
**Post date:** [February 28, 2024, 5:52pm UTC](https://community.stereolabs.com/t/zed-camera-does-not-open-in-docker-container-as-a-non-root-user/2259/11 "2024-02-28T17:52:30Z")

</div>

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](https://www.stereolabs.com/)/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.
