jozo / docker-pyqt5

Dockerfile for development of GUI applications with Python 3 + PyQt5
84 stars 24 forks source link

Error: Could not connect to display #2

Open adrifoster opened 4 years ago

adrifoster commented 4 years ago

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!

jozo commented 4 years ago

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.

adrifoster commented 4 years ago

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...

jozo commented 4 years ago

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.

msm-sardar commented 4 years ago

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 \
jozo commented 4 years ago

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/