Search code examples
dockerxserver

Docker cannot connect to X server


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.


Solution

  • 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?