c0b / docker-elixir

Official Docker image for Elixir :whale: :turtle: :rocket:
http://elixir-lang.org/
190 stars 74 forks source link

Can't user :observer.start inside container #77

Open hopewise opened 6 years ago

hopewise commented 6 years ago

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?

c0b commented 6 years ago

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

chulkilee commented 6 years ago

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

--

Update: please run the commands in X11 terminal

c0b commented 6 years ago

@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

hopewise commented 6 years ago

yes, it did not work for me

khelll commented 5 years ago

The solution proposed by @chulkilee is actually working, however, please note that you have to run everything through the X11 terminal:

screen shot 2019-01-29 at 11 44 03 am

nulian commented 5 years ago

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 debug@node.example.com -setcookie OURERLANGCOOKIE -run observer

Then in the observer menu switch to that node.