Running OpenModelica GUI from Docker causes "Could not connect to any X display" error

On Modelica Language Discord, someone posted the commands to get the OpenModelica GUI (OMEdit) running on Linux:

xhost +"local:docker@"
docker run -ti --rm --privileged --net=host -e "DISPLAY=$DISPLAY" -v /tmp/.X11-unix:/tmp/.X11-unix openmodelica/openmodelica:v1.14.1-gui OMEdit

and someone else posted the below command for macOS:

docker run -ti --rm --privileged --net=host -e DISPLAY=docker.for.mac.localhost:0 -v /tmp/.X11-unix:/tmp/.X11-unix openmodelica/openmodelica:v1.14.1-gui OMEdit

I have installed Docker using HomeBrew following the instructions here

docker --version
Docker version 19.03.8, build afacb8b

but when trying the command above I get the error message:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
qt.qpa.screen: QXcbConnection: Could not connect to display docker.for.mac.localhost:0
Could not connect to any X display.

Things I have tried to solve the problem:

  • from here installed dbus brew install dbus
  • from here ran xhost +local:docker returning

non-network local connections being added to access control list

  • from here and here changed DISPLAY=unix$DISPLAY leading to slightly different error

qt.qpa.screen: QXcbConnection: Could not connect to display unix/private/tmp/com.apple.launchd.lO0ZFXT603/org.macosforge.xquartz:0

  • from here, I tried
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
docker run .... -e DISPLAY=$(xhost + $(hostname) > /dev/null; echo $IP):0 ...

leading to

qt.qpa.screen: QXcbConnection: Could not connect to display 10.0.0.9:0

  • from here, I tried the open -a XQuartz, ... xhost + $ip, and DISPLAY=$ip:0

I would appreciate if you could help me know

  • How can I resolve the above issues and get the GUI running
  • breakdown down the above commands for me. some of them are explained here, but not the rest.

P.S. I don't want to install Docker Desktop as discussed here.


Solution 1:

OK, I think I was able to solve the problem. I assume XQuartz and socat are installed

brew cask install xquartz
brew install socat

then from here, run

socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"

in one terminal. Open a new terminal and run

docker-machine env default
eval $(docker-machine env default)
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $IP
docker run -ti --rm --privileged --net=host -e DISPLAY=$IP:0 -v /tmp/.X11-unix:/tmp/.X11-unix openmodelica/openmodelica:v1.14.1-gui OMEdit

But still, I would appreciate it if someone could explain what these commands do and if there is a more clean and canonical way to do it.

P.S. Please consider that the docker-machine is deprecated software as of now. Please use it at your own risk. You need to follow these instructions to get it up and running.