Cross-Host Communication: Ambassador pattern versus port exposition

2 min read Original article ↗

I couldn't find any other way to establish cross-host communication between two Docker containers (at this moment) than using the Ambassador pattern proposed here.

I am wondering what are the advantages of using this pattern over the simple use of port exposition provided by Docker. Here's an example on how I use the port exposition technique:

Node A

ifconfig eth0 192.168.56.101
docker run -i -t -p 5558 --name NodeA ubuntu /bin/bash

Then the local port, to the Docker container: 5558 maps to the physical port 49153 of the host.

(5558 --> 49153)

Node B

ifconfig eth0 192.168.56.103
docker run -i -t -p 5558 --name NodeB ubuntu /bin/bash

Then the local port, to the Docker container: 5558 maps to the physical port 49156 of the host.

(5558 --> 49156)

*The port mapping from the Docker container to the physical port can be forced by using -p 5558:5558

Cross-Host Container Communication

Then NodeA can communicate with NodeB, container to container, through the following ip address:

192.168.56.103:49156

And NodeB can listen on port 5558 from inside the container.

Conclusion

This seems like a straight-forward way to achieve this kind of communication, although it very much feels like a hack around the concept of containers. My question is why use one option over the other and also does it actually break the concept of isolation from the host?