Enable connection between Erlang VMs from different docker containers on different hosts by reimplementing the distributed connection protocol used by net_kernel.
Erlang
158
11 commits
updated Jun 14, 2015
Enable Erlang connection among distributed dockers (docker containers on different hosts) by reimplementing the distributed connection protocol of net_kernel.
Erlang nodes need connect with each other to work together, so they are usually used in one subnet. However, dockers on different hosts are in different subnets (one subnet per host). So it's difficult to build Erlang cluster on distributed docker cluster.
When an Erlang node attempts to connect another node, it must create a tcp connection to the node. Because different Erlang nodes listen on different ports, there should be a naming service with a known port which can tell us the port of a Erlang node. That's epmd.
The following figure shows the connection buiding process of Erlang nodes:

It is difficult to connect nodes among distributed dockers, because:
-P or -p xxx:xxx to fix the port mapping, we can start only one docker with Erlang on one host because of port conflict. If we use -p xxx to map the port to an arbitrary host port, we can only get the published port from the docker daemon.In this project, we implement a new connection protocol module eid_tcp_dist.erl instead of inet_tcp_dist.erl. The following figure shows the new protocol of Erlang connection.
We mainly did the following modifications on the connection protocol:
DockerContainerID@HostIP.Docker Remote API should be enabled by following steps:
DOCKER_OPTS="-H tcp://0.0.0.0:4243" in /etc/default/docker.io or /etc/default/docker.sudo service docker restart.PS:
4243is the default port used by docker HTTP API. It can also be set to some other value such as4321, but eid should be configured the same docker port value by adding-kernel docker_dameon_port 4321when starting Erlang VM.
You must ensure you have an erlang environment on your computer.
You can compile and install Erlang-In-Docker with the simple command ./build %target_path%, for example:
./build /usr/lib/erlang
After the installation, a complete Erlang environment with eid started automatically is installed to %target_path%.
-p 12345 to export and publish the port used by Erlang node.-proto_dist eid_tcp to enable eid_tcp_dist instead of inet_tcp_dist.PS:
12345is the default port used by Erlang node. It can also be set to some other value such as1234, but eid should be configured the same erlang port value by adding-kernel erlang_port 1234when starting Erlang VM.
For example, the command should be like this:
sudo docker run -i -t -p 12345 %image_name% /bin/bash
%target_path%/erl -proto_dist eid_tcp -name asd134fczcv@192.168.4.231 -setcookie taotaotheripper
PS:
asd134fczcvis the container ID,192.168.4.231is the IP of the host.
As is mentioned before, when starting Erlang node, you can use kernel envrionment value docker_daemon_port to specify the docker HTTP port Erlang-In-Docker will request, erlang_port to specify the port Erlang node will use in docker. For example:
# DOCKER_OPTS="-H tcp://0.0.0.0:4321
sudo docker run -i -t -p 1234 %image_name% /bin/bash
%target_path%/erl -proto_dist eid_tcp -name asd134fczcv@192.168.4.231 -setcookie taotaotheripper -kernel docker_daemon_port 4321 erlang_port 1234
11 commits
Erlang
100.0%
Enable connection between Erlang VMs from different docker containers on different hosts by reimplementing the distributed connection protocol used by net_kernel.
Erlang
158
11 commits
updated Jun 14, 2015
Enable Erlang connection among distributed dockers (docker containers on different hosts) by reimplementing the distributed connection protocol of net_kernel.
Erlang nodes need connect with each other to work together, so they are usually used in one subnet. However, dockers on different hosts are in different subnets (one subnet per host). So it's difficult to build Erlang cluster on distributed docker cluster.
When an Erlang node attempts to connect another node, it must create a tcp connection to the node. Because different Erlang nodes listen on different ports, there should be a naming service with a known port which can tell us the port of a Erlang node. That's epmd.
The following figure shows the connection buiding process of Erlang nodes:

It is difficult to connect nodes among distributed dockers, because:
-P or -p xxx:xxx to fix the port mapping, we can start only one docker with Erlang on one host because of port conflict. If we use -p xxx to map the port to an arbitrary host port, we can only get the published port from the docker daemon.In this project, we implement a new connection protocol module eid_tcp_dist.erl instead of inet_tcp_dist.erl. The following figure shows the new protocol of Erlang connection.
We mainly did the following modifications on the connection protocol:
DockerContainerID@HostIP.Docker Remote API should be enabled by following steps:
DOCKER_OPTS="-H tcp://0.0.0.0:4243" in /etc/default/docker.io or /etc/default/docker.sudo service docker restart.PS:
4243is the default port used by docker HTTP API. It can also be set to some other value such as4321, but eid should be configured the same docker port value by adding-kernel docker_dameon_port 4321when starting Erlang VM.
You must ensure you have an erlang environment on your computer.
You can compile and install Erlang-In-Docker with the simple command ./build %target_path%, for example:
./build /usr/lib/erlang
After the installation, a complete Erlang environment with eid started automatically is installed to %target_path%.
-p 12345 to export and publish the port used by Erlang node.-proto_dist eid_tcp to enable eid_tcp_dist instead of inet_tcp_dist.PS:
12345is the default port used by Erlang node. It can also be set to some other value such as1234, but eid should be configured the same erlang port value by adding-kernel erlang_port 1234when starting Erlang VM.
For example, the command should be like this:
sudo docker run -i -t -p 12345 %image_name% /bin/bash
%target_path%/erl -proto_dist eid_tcp -name asd134fczcv@192.168.4.231 -setcookie taotaotheripper
PS:
asd134fczcvis the container ID,192.168.4.231is the IP of the host.
As is mentioned before, when starting Erlang node, you can use kernel envrionment value docker_daemon_port to specify the docker HTTP port Erlang-In-Docker will request, erlang_port to specify the port Erlang node will use in docker. For example:
# DOCKER_OPTS="-H tcp://0.0.0.0:4321
sudo docker run -i -t -p 1234 %image_name% /bin/bash
%target_path%/erl -proto_dist eid_tcp -name asd134fczcv@192.168.4.231 -setcookie taotaotheripper -kernel docker_daemon_port 4321 erlang_port 1234
11 commits
Erlang
100.0%