Connecting a local Elixir/Erlang to a running application inside a Docker container
Asked Answered
S

1

6

I've got an Elixir application running inside a Docker container (in my laptop). The Elixir application was executed with the following command:

iex \
  --name [email protected] \
  --cookie secret \
  --erl '-kernel inet_dist_listen_min 9000'  \
  --erl '-kernel inet_dist_listen_max 9000' \
  -S mix phx.server

And the Docker container exposes the following ports:

0.0.0.0:4000->4000/tcp, 0.0.0.0:4369->4369/tcp, 0.0.0.0:9000->9000/tcp

  • 4000 for the Phoenix server
  • 4369 for EPMD
  • 9000 for the VM node

Then I try to connect using an IEx shell using the following command:

iex --name [email protected] --cookie secret which results in this error: Protocol 'inet_tcp': register/listen error: epmd_close

This seems to be because the local epmd daemon is trying to allocate to port 4369, however, this is already allocated to the Docker container.

I then changed the EPMD port like so:

ERL_EPMD_PORT=4370 iex --name [email protected] --cookie secret

and I manage to open up the IEx session. However, I cannot find the node running on the Docker container:

iex([email protected])1> Node.connect :'[email protected]'
false

I'm not sure how to solve this. I was following this blog post.

Sturdy answered 27/2, 2018 at 15:29 Comment(1)
Not sure if it applies but this previous S O answer may have some bearing on your issue.Havens
B
2

Wouldn't an easier solution be to change the outward port of the docker container? Just change it to something like 4368

$ docker run -itd -p 4000:4000 4368:4369 9000:9000 <docker_image_name> iex \
  --name [email protected] \
  --cookie secret \
  --erl '-kernel inet_dist_listen_min 9000'  \
  --erl '-kernel inet_dist_listen_max 9000' \
  -S mix phx.server`
Burkitt answered 27/2, 2018 at 17:41 Comment(2)
Thanks for the reply, but this doesn't seem to help with the issueSturdy
can you specify a port for the node to connect to? Like: iex([email protected])1> Node.connect :'[email protected]:4368'Burkitt

© 2022 - 2024 — McMap. All rights reserved.