docker-elixir
docker-elixir copied to clipboard
Can't user :observer.start inside container
I run phoenix server into container at Mac, I run the container as:
docker run -p 4011:4011 -p 4033:4033 -v ~/.Xauthority:/root/.Xauthority -v /Users/samir/Documents/projects/elixir:/usr/src -e DISPLAY=$DISPLAY --network host -it elixir:1.5.2 bash
then, when I start phoenix as:
iex -S mix phx.server
I got error when try to run :observer.start
:
iex(1)> :observer.start 13:50:45: Error: Unable to initialize GTK+, is DISPLAY set properly? {:error, {{:einval, 'Could not initiate graphics'}, [{:wxe_server, :start, 1, [file: 'wxe_server.erl', line: 65]}, {:wx, :new, 1, [file: 'wx.erl', line: 115]}, {:observer_wx, :init, 1, [file: 'observer_wx.erl', line: 98]}, {:wx_object, :init_it, 6, [file: 'wx_object.erl', line: 372]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]}}
inside container:
$ echo $DISPLAY
/private/tmp/com.apple.launchd.xdi35OUtZR/org.macosforge.xquartz:0
Any idea?
it's the XWindow protocol not mismatch, for me I I run Linux as the main developer OS only, on Mac hardware and other PC laptops, I like the Mac hardware only not its OSX, have no idea how to make that DISPLAY
work with the XWindow protocol;
https://github.com/c0b/docker-elixir/wiki/use-observer <= this is how do I make it working, I believe the
XWindow protocol's DISPLAY
is something like DISPLAY=<hostname>:X.Y
not sure what are the proprietary changes made by the OSX;
you may continue research with your solution to make it natively working, or one possible direction is to have a VNC Server running on mac-os , most VNC Server do have the XWindow compliant DISPLAY https://apple.stackexchange.com/questions/303647/vnc-server-for-mac-os
That $DISPLAY
path is not available in container, since you don't mount that. The docker container has access to host network interface (with --net host
), but not file system.
I'm not expert on this, but following works for me:
# run XQuartz
# check XQuartz => Preferences => Security => Allow connections from network clients
# restart XQuartz
xhost + 127.0.0.1
docker run \
-it \
--rm \
-e DISPLAY=host.docker.internal:0 \
elixir:latest iex -e ":observer.start()"
Links
- https://medium.com/@mreichelt/how-to-show-x11-windows-within-docker-on-mac-50759f4b65cb
- https://docs.docker.com/docker-for-mac/networking/
--
Update: please run the commands in X11 terminal
@hopewise can confirm that? then we may add a section into the wiki page, and a link to the README.md
https://github.com/c0b/docker-elixir/wiki/use-observer
yes, it did not work for me
The solution proposed by @chulkilee is actually working, however, please note that you have to run everything through the X11 terminal:
It's also possible through tunneling which can be done without X11
You need to make a tunnel through port 4369 and the port in epmd -names
If the server is using full name you need to set that dns on your local machine on 127.0.0.1
erl -name [email protected] -setcookie OURERLANGCOOKIE -run observer
Then in the observer menu switch to that node.