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
-Sflag executes the given script in path, and can be used instead of running the script directly through both theelixirandiexexecutables. The following commands are equivalent:mix phx.server
elixir -S mix phx.server
Running a command through the
elixirexecutable is useful, becauase it takes more arguments, like the--snameone described above.The
iexexecutable also takes an-Sflag. To start the Phoenix server with an iEX session attached, run themix phx.servercommand throughiex:↩︎iex -S mix phx.server
- https://www.erlang.org/doc/reference_manual/distributed.html ↩︎