Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the Erlang Observer App with a remote Elixir Phoenix server inside Docker

What I am trying to do is to run the Erlang Observer App locally and then connect to a remote Docker container that is running my Elixir/Phoenix app in production.

The problem I am having is not being able to connect.

From my research it seems that I need to know the IP address of the Docker image before starting the Phoenix server, so that I can start it like so:

iex --name [email protected] -S mix phoenix.server

I'm not sure whether a cookie is needed, so I've also tried

iex --name [email protected] --cookie random_cookie -S mix phoenix.server

I've tried using a hostname instead of an IP address, that did not seem to work.

Once I have that running then I expect to run Observer like this

erl -name [email protected] -setcookie random_cookie -run observer

Or, with IEx

iex --name [email protected] --cookie random_cookie

iex> :observer.start()

Can I start a Phoenix server without needing to know the IP address and still be able to remotely connect with Observer?

I can figure out what the IP address will be of the docker image during building it up with this shell command

ip addr | grep -Eo 'inet (.*) scope global' | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'

But can't figure out how to put this in the command to start the Phoenix server.

I know there is a possible solution with starting up docker images with static IP address, but I cannot set static IP addresses with my setup.

Any help is appreciated.

like image 353
shdblowers Avatar asked Nov 09 '22 02:11

shdblowers


1 Answers

Can I start a Phoenix server without needing to know the IP address and still be able to remotely connect with Observer?

Yes, with DNS you can. Of course you will at least need to know the fully qualified domain name of the server running the Erlang node. While not quite as short as an Erlang node short name (e.g. node@server) it's still probably better than an IP address. I'm not too familiar with Docker, so it may be easier to stick with an IP address. In this situation it doesn't get you a whole lot.

Once I have that running then I expect to run Observer like this

erl -name [email protected] -setcookie random_cookie -run observer

What server are you running this command on? It will need to be on a machine that has Erlang compiled with Wx support. If this is on a different machine than the one you are running your Phoenix server on this will not work (which is what I understand to be the case).

You will need to do something like this instead:

  1. Find the epmd port on the container running phoenix

    $ ssh phoenix-host "epmd -names"
    epmd: up and running on port 4369 with data:
    name some_phoenix_node at port 58769
    

    Note the port for epmd itself and the port of the node you're interested in debugging. Reconnect to the phoenix host with the ports you found forwarded:

    $ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 phoenix-host
    
  2. On your machine, start a hidden Erlang node running the observer app:

    $ iex -name [email protected] -setcookie <phoenix-server-cookie> -hidden -run observer
    

    The app should open up and you should be able to select the node running the phoenix server.

Source: https://gist.github.com/pnc/9e957e17d4f9c6c81294

Update 2/20/2017

I wrote a script that can do the above automatically. All ports epmd knows about are forwarded to localhost: https://github.com/Stratus3D/dotfiles/blob/master/scripts/tools/epmd_port_forwarder

like image 60
Stratus3D Avatar answered Nov 15 '22 06:11

Stratus3D