Host name is illegal, when trying to connect two nodes (docker containers)

No error when starting nodes with ip address

iex --name "machine1@172.25.0.7" --cookie supersecret
iex --name "machine2@172.25.0.8" --cookie supersecret```

They connect well using Node.connect()

When trying to start the node in code via Node.start(:"machine1@172.25.0.7"), i get an error stating

System NOT running to use fully qualified hostnames **
** Hostname 172.25.0.7 is illegal **

If it’s a release, they use -sname (short name) by default.

1 Like

I think by default they use longnames Node.start/3

That function is not really relevant to releases though. When a release is started, net_kernel is started with it, Node.start does not have effect then. And releases use sname by default. That’s only relevant if you are running in a release.

See mix release — Mix v1.12.3, search for RELEASE_DISTRIBUTION.

1 Like

Actually am using bakeware to for creating an executable file. When i run that executable then i counter this issue. Is generating a binary a release ?

If yes then whats the best way to resolve this issue ?

using the sname when i start the nodes on docker containers

iex --sname machine1 --cookie supersecret
iex --sname machine2 --cookie supersecret

when i try to connect them

Node.connect(:"machine2@2635b841aa30")

i get false

If you don’t use host networking in docker, then they won’t be able to connect to each other anyway since they have separate epmds running in each container. For erlang distribution to work out of the box (default setup), they need to have access to epmd running on port 4369 on each host (the part after @ in the node name, like 172.25.0.8). They ask epmd for nodes running on that host and what ports they use and then connect to them.

More info:

epmd is kind of like local service discovery, and there are ways to skip epmd and connect the nodes directly, if something else is used for service discovery (like etcd/consul/dns): Erlang Distribution Without epmd

2 Likes

Thank you so much. Is there any link that you can share to learn about it more ?

Thank you, i will have a look at it

I haven’t used bakeware yet, so can’t really help on that part. I have a repo inspired by Elixir Multi-AZ Clustering Case Study | SkillsCast | 29th November 2017 and ElixirConf 2021 - Mark Ericksen - Globally Distributed Elixir Apps on Fly.io - YouTube where I use releases inside docker containers and specify the env vars for the release to start with the long name I want: try-ecs/env.sh.eex at 520f49f300a50d8930b2c2be4fc4c1924c795a5a · ruslandoga/try-ecs · GitHub

Then I use host networking in docker (it’s icky but seems to work) for containers to be able to share a single epmd instance on the host.

try-ecs/rel at master · ruslandoga/try-ecs · GitHub – these and some other files are generated with mix release.init