Connect erlang nodes on docker Connect erlang nodes on docker docker docker

Connect erlang nodes on docker


This is how you would do it without docker-compose for Erlang nodes.

1. Create the network

docker network create example

2. Start docker containers

Terminal 1

$ docker run --rm -it --name bar -h bar --net example erlang:19.3 /bin/bashroot@bar:/# erl -sname bar -setcookie exampleErlang/OTP 19 [erts-8.3.5.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]Eshell V8.3.5.1  (abort with ^G)(bar@bar)1>

Terminal 2

docker run --rm -it --name foo -h foo --net example erlang:19.3 /bin/bashroot@foo:/# erl -sname foo -setcookie exampleErlang/OTP 19 [erts-8.3.5.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]Eshell V8.3.5.1  (abort with ^G)(foo@foo)1>

3. Check connectivity

Terminal 1

(foo@foo)1> net_adm:ping(bar@bar).pong

Terminal 2

(bar@bar)1> net_adm:ping(foo@foo).pong

Getting a remote shell for a release running on a docker container

1. Start a bash shell in one of the two docker containers

docker exec -it foo /bin/bash

Where foo is the name for the docker container.

2. Start a remote shell

./rel/your_app/bin/your_app console

I assume you know the path to the release inside the container.


Use docker-compose.

Something like this:

docker-compose.yml:

version: "3"services:  elixir1:    image: image-name    #(other configs here, like ports, volumes)  elixir2:    image: image-name    #(other configs here, like ports, volumes)

Then, you are able to point DNS elixir1 and elixir2 with that names among them.

Replace your docker run commands with:

docker-compose up