Start a GUI-Application as root in a Ubuntu Container

Hello Community,

I’m trying to create a docker container FROM ubuntu:latest where a GUI-Application is running in.
The application needs to get executed with sudo to access the inside used commands.
I followed the instruction of this Blog and adapted it for my use.

After i build this container I first ran it with:
docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix repo-test-3 /bin/bash
then
./applicatin
and the application is shown at the screen.

The next I tried to run the same container with -u 0 to become root and after i tried to start the application the following error message appears:
No protocol specified QXcbConnection: Could not connect to display :0 Aborted (core dumped)

Do you have any idea whats the problem and how I can fix this?

Best regards,
Daniel E.

EDIT:
The Solution of the problem:

Give docker the rights to access the X-Server with:

xhost +local:docker

1 Like

Thanks.You help me a lot,and just use the commad ‘xhost +local:docker’ on the localhost machine.

Thanks a lot, It’s really help for me.

Thank you very much! It’s the only helpful answer in internet. It’s really help for me!

This is very helpful.

Thank you, it helped me alot.