[英]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. 我想要做的是在本地运行Erlang Observer App然后连接到生产中运行我的Elixir / Phoenix应用程序的远程Docker容器。
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: 根据我的研究,我似乎需要在启动Phoenix服务器之前知道Docker镜像的IP地址,以便我可以像这样启动它:
iex --name my_app@10.20.57.123 -S mix phoenix.server
I'm not sure whether a cookie is needed, so I've also tried 我不确定是否需要cookie,所以我也试过了
iex --name my_app@10.20.57.123 --cookie random_cookie -S mix phoenix.server
I've tried using a hostname instead of an IP address, that did not seem to work. 我尝试过使用主机名而不是IP地址,这似乎不起作用。
Once I have that running then I expect to run Observer like this 一旦我运行了那么我希望像这样运行Observer
erl -name observe@127.0.0.1 -setcookie random_cookie -run observer
Or, with IEx 或者,使用IEx
iex --name observe@127.0.0.1 --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? 我可以在不需要知道IP地址的情况下启动Phoenix服务器,并且仍然能够与Observer远程连接吗?
I can figure out what the IP address will be of the docker image during building it up with this shell command 在使用此shell命令构建它时,我可以弄清楚docker镜像的IP地址是什么
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. 但无法弄清楚如何将此命令用于启动Phoenix服务器。
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. 我知道有一个可能的解决方案,启动具有静态IP地址的docker镜像,但我无法使用我的设置设置静态IP地址。
Any help is appreciated. 任何帮助表示赞赏。
Can I start a Phoenix server without needing to know the IP address and still be able to remotely connect with Observer? 我可以在不需要知道IP地址的情况下启动Phoenix服务器,并且仍然能够与Observer远程连接吗?
Yes , with DNS you can. 是的 ,您可以使用DNS。 Of course you will at least need to know the fully qualified domain name of the server running the Erlang node. 当然,您至少需要知道运行Erlang节点的服务器的完全限定域名。 While not quite as short as an Erlang node short name (eg node@server
) it's still probably better than an IP address. 虽然不像Erlang节点短名称(例如node@server
)那么短,但它仍然可能比IP地址更好。 I'm not too familiar with Docker, so it may be easier to stick with an IP address. 我对Docker不太熟悉,因此坚持使用IP地址可能更容易。 In this situation it doesn't get you a whole lot. 在这种情况下,它并没有给你带来太多。
Once I have that running then I expect to run Observer like this 一旦我运行了那么我希望像这样运行Observer
erl -name observe@127.0.0.1 -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. 它需要在具有Wx支持的Erlang编译的机器上。 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: 你需要做这样的事情:
Find the epmd port on the container running phoenix 在运行phoenix的容器上找到epmd端口
$ 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. 请注意epmd本身的端口以及您要调试的节点的端口。 Reconnect to the phoenix host with the ports you found forwarded: 使用您找到的端口重新连接到phoenix主机:
$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 phoenix-host
On your machine, start a hidden Erlang node running the observer app: 在您的计算机上,启动一个运行观察者应用程序的隐藏Erlang节点:
$ iex -name debug@127.0.0.1 -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 资料来源: https : //gist.github.com/pnc/9e957e17d4f9c6c81294
Update 2/20/2017 2017年2月20日更新
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 epmd知道的所有端口都转发到localhost: https : //github.com/Stratus3D/dotfiles/blob/master/scripts/tools/epmd_port_forwarder
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.