k-p
I have an Elixir app running on a remote server using Dokku. I’d like to connect to it from my local machine using Livebooks, via a SSH tunnel.
I can’t seem to make the remote container visible to my local Livebook.
I’ve tried the top StackOverflow comments and have tried setting RELEASE_NODE, RELEASE_NAME, and RELEASE_DISTRIBUTION. I have RELEASE_COOKIE configured and am using this.
I have tried using RELEASE_NODE as <app_name>@localhost, <app_name>@127.0.0.1, and <app_name>@<server_ip>.
I gather there’s some shenanigans trying to get EPMD to see the remote node. I’ve tried setting ERL_DIST_PORT to 9000, forwarding Dokku’s host 9000 to the container’s 9000, and opening an SSH tunnel with 9000 open.
Is there a straightforward-ish solution or problem I’m missing? I appreciate there’s a few moving parts.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
jonatanklosko
Hey @k-p! There are a few elements
The remote node needs to start distribution on a known port. I believe
ERL_DIST_PORTis used by rebar3/relx, not the Elixir releases. To force a specific port you can doELIXIR_ERL_OPTIONS="-erl_epmd_port 9000"(or pass it in vm.args).The distribution port needs to be forwarded to a local port, let’s assume it’s the same.
The remote node needs to have 127.0.0.1 hostname (or if it uses a domain name, you can edit your local
/etc/hoststo resolve it to 127.0.0.1).With the above steps, the node appears as if it was running locally. However, the missing piece is that the local EPMD doesn’t know about this node. You can register the node manually by running this script:
Make sure to change the node name at the end, it should be the base name, without the hostname part. The registration is kept until you kill the script.
Technically steps 3. and 4. could be done by using a custom EPMD module, but since we are talking about Livebook, the solution assumes no changes to the EPMD module. (In fact, Livebook already uses a custom EPMD for a similar purpose).
k-p
Hello! Thanks for your help and your script to register the node.
I make it as far as seeing connection refused in the SSH tunnel when I attempt to connect to the node so I can see Livebook is trying to connect over the port to the remote node. But I think it’s still stuck somewhere between 1-3.
I’m quite a novice with distributed Elixir, apologies. If I enter the container, and run epmd -names I can see that epmd is still running on port 4369 and the node (name app at port 9000) is running on port 9000, with the config set in step one. Is that right? The argument to me reads as though epmd should be on port 9000.
jonatanklosko
Just to make sure, you are using
RELEASE_DISTRIBUTION=name,RELEASE_NODE=app@127.0.0.1and the same cookie?This is correct. The argument name is confusing, and in fact it’s going to change in the next OTP version. It is supposed to set the port that the node uses for distribution, not the EPMD port itself. So
name app at port 9000looks good.If the connection is refused, the only thing I can think of is something with the forwarding. For the ssh forwarding maybe try
127.0.0.1and notlocalhost, unless you already do that. Otherwise it could be the port forwarding to Docker.Awea
Hey, I’m trying to do the same thing without the ssh tunnel part.
So far I can connect a local iex session to the remote node (with
Node.connect) but only using it’s IP, using it’s hostname won’t work for some reason (while a local iex session with--remsh app@example.comworks).And I can’t get working livebook locally with my remote node, I started it with the
LIVEBOOK_NODE,LIVEBOOK_DISTRIBUTIONandERL_AFLAGSbut no luck livebook won’t connect to the remote node.Any idea what the problem might be? I found another topic which look like my issue but my mtu is already set at 1500 so no luck either here.
Awea
Ok found it, starting livebook without the
ERL_AFLAGSand now it connects!Here is my configuration for anyone looking for the same thing:
Release
Create
rel/remote.vm.args.eexwith:So that
docker compose exec app bin/app remoteworksRemote
Local
_jonas
I’m trying to better understand how to connect a local BEAM node to one running on a remote server in a container, for debugging and inspecting the system and such (not necessarily with livebook), and I still don’t really get it
I don’t get why this why this works, I thought
erl_epmd_portsets the port that epmd listens on (epmd — OTP 29.0.2 (erts 17.0.2)) not the distribution port of the node itself? What am I missing?jonatanklosko
@_jonas you linked to
ERL_EPMD_PORTenv var, which indeed sets the port for epmd to listen on. However, the-erl_epmd_portflag sets the node distribution port. The fact that they are named the same is unfortunate, however in recent OTP the flag has been deprecated in favour of kernel application parameter namederl_epmd_node_listen_port, which is more accurate._jonas
Ohhh that makes sense, thanks for explaining!
Good thing it’s being changed to that less confusingly named flag, I would have never guessed
So just to summarize what I’ve gathered for myself then:
erl_epmd_node_listen_portjonatanklosko
If you set
-erl_epmd_port(or the newerl_epmd_node_listen_port) for the local node, then it’s going to assume this port is used by all nodes it connects to.The issue is that if you are using a proxy, let’s say
127.0.0.1:4444 -> remote.node:5555, then you would need to set-erl_epmd_port 4444, but the local node cannot start distribution at that port, since it’s already taken by the proxy._jonas
Ah, that is good to know!
I thought when running without epmd, there would be some way to manually specify the distribution port of another node to connect to, similar to how you would normally specify the name.
I guess I was mistaken – then I suppose your suggested way of running with a local epmd and registering the remote node manually is indeed the best option, thanks again for explaining.