Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker cannot connect to X server

Tags:

docker

xserver

I have created a docker image for opencv and facial reckognition to simplify the setup process.

But the recognize.py script needs X Server to show the image result. Here is what I have done so far:

sudo docker run -t -d --name opencv opencv:latest
sudo docker exec -it opencv bash /extract-embeddings.sh
sudo docker exec -it opencv bash /train-model.sh

All is fine so far. The last step is the actual comparison that displays the result in an image.

sudo docker exec -it opencv bash /face-recognition.sh

It gives the output:

[INFO] loading face detector...
[INFO] loading face recognizer...
No protocol specified
: cannot connect to X server :0

I have tried running the container with the following command:

sudo docker run -t -d --name opencv -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix opencv:latest

But it doesn't help.

like image 224
Kasper Hansen Avatar asked Jul 08 '19 09:07

Kasper Hansen


Video Answer


2 Answers

Try running this,

xhost +

sudo docker run --rm -ti --net=host --ipc=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --env="QT_X11_NO_MITSHM=1" <image_name> <arguments>

Other might face issue regarding the image not getting rendered on screen or getting a blank screen with no image, for them add --env="_X11_NO_MITSHM=1" to the above script while running the docker image. It will solve the problem.

For further information, I would recommend you guys check out the below references.

Reference 1
Reference 2

like image 194
Afroz Chakure Avatar answered Oct 16 '22 12:10

Afroz Chakure


It looks like the xauth is the issue for viewing of the image. The details are at Can you run GUI applications in a Docker container?

like image 34
lokrao Avatar answered Oct 16 '22 14:10

lokrao