docker-pyqt5 icon indicating copy to clipboard operation
docker-pyqt5 copied to clipboard

Error: Could not connect to display

Open adrifoster opened this issue 4 years ago • 5 comments

Hi,

I am trying to test out this Dockerfile but can't seem to get it to work. I ran the command as you said in your README, but got this error:

acfoster@Adriannas-MacBook-Pro docker-pyqt5 % docker run -it \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v $(pwd)/test:/app \
    -e DISPLAY=$DISPLAY \
    -u qtuser \
    fadawar/docker-pyqt5 python3 /app/hello.py
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-qtuser'
qt.qpa.screen: QXcbConnection: Could not connect to display /private/tmp/com.apple.launchd.nJM1c2qxF5/org.macosforge.xquartz:0
Could not connect to any X display.

I am trying to build this on a Mac running macOS 10.15.5 (Catalina)

Thank you!

adrifoster avatar Jul 14 '20 15:07 adrifoster

Hi, the problem here is that you are using macOS. It doesn't have X11 server by default. But you can install and use XQuartz. Here is nice tutorial how to do it: https://sourabhbajaj.com/blog/2017/02/07/gui-applications-docker-mac/

Let me know if you were succesful with it.

jozo avatar Jul 14 '20 19:07 jozo

I actually do have XQuartz. I think I fixed it via:

  1. In XQuartz: Check the option: XQuartz -> Preferences -> Security -> "Allow connections from network clients"

  2. Then run in terminal:

IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $IP
  1. I then changed your command for the DISPLAY to

-e DISPLAY=$IP:0 \

It seems to work now! I am developing my container to give to some end-users who probably aren't really familiar with using the terminal and such, do you know if there is a way to add these DISPLAY and -v commands to the Dockerfile? Sorry I am new to Docker...

adrifoster avatar Jul 14 '20 20:07 adrifoster

You can add -e (environment variables) to Dockerfile. You can use ENV for that (check docs). You can't define -v commands in Dockerfile. Instead of that you can COPY your files to Dockerfile (check docs).

There is a problem with defining IP address of XQuartz in Dockerfile. If IP address change, you'll have to again use -e to overwrite it to correct IP address.

jozo avatar Jul 15 '20 06:07 jozo

I got the same error. I am running the docker on windows 10.

(base) C:\Users\msmsa\Downloads\docker-pyqt5-master>docker run -v /tmp/.X11-unix:/tmp/.X11-unix -v C:/Users/msmsa/Downloads/docker-pyqt5-master/test:/app -e DISPLAY=unix$DISPLAY -u qtuser fadawar/docker-pyqt5 python3 /app/hello.py
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-qtuser'
qt.qpa.screen: QXcbConnection: Could not connect to display unix$DISPLAY
Could not connect to any X display.

and what does the following option do? why do we need it?

-v /tmp/.X11-unix:/tmp/.X11-unix \

msm-sardar avatar Jul 17 '20 01:07 msm-sardar

and what does the following option do? why do we need it?

-v /tmp/.X11-unix:/tmp/.X11-unix \

It's socket file for X11 server. To use X11 on windows you can check this article: https://cuneyt.aliustaoglu.biz/en/running-gui-applications-in-docker-on-windows-linux-mac-hosts/

jozo avatar Jul 18 '20 08:07 jozo