To be able to attach to a running Elixir instance, the process first needs to have a name set to refer to.1
For example, a Phoenix application is usually started by running the mix phx.server
command.
Instead, start it through the elixir
executable via the -S
flag.2
The command also includes the --sname
flag (for short name), which is used to refer to the process later.3
elixir --sname phoenix -S mix phx.server
Then, to connect to the node, use the --remsh
(for remote shell) command to refer to the running phoenix process:
iex --sname console --remsh phoenix
- https://elixir-lang.org/getting-started/mix-otp/distributed-tasks.html#our-first-distributed-code ↩︎
The
-S
flag executes the given script in path, and can be used instead of running the script directly through both theelixir
andiex
executables. The following commands are equivalent:mix phx.server
elixir -S mix phx.server
Running a command through the
elixir
executable is useful, becauase it takes more arguments, like the--sname
one described above.The
iex
executable also takes an-S
flag. To start the Phoenix server with an iEX session attached, run themix phx.server
command throughiex
:iex -S mix phx.server
- https://www.erlang.org/doc/reference_manual/distributed.html ↩︎