Bind #Docker container ports to virtual interfaces to simulate cluster nodes

By | November 8, 2017

My setup implies that I have 3 almost identical application nodes (running as containers) that are part of a cluster and they need to be mapped to different external IPs (not part of the docker ingress network) because they are added in a cluster configuration external to docker.

The default behavior of port binding is to bind a port to the localhost more specific to
This can be done very easy using docker-compose:

This is not OK for my setup because I need to map the same exact ports for all the nodes.

For this I have to simulate somehow 3 actual physical machines on my test environment.

Virtual interfaces to the rescue:

The first step was to define 3 virtual network interfaces defined over my real lan interface enp2s0:

The result of the above can be seen with ifconfig as:

Now we can bind each specific application node to a virtual interface. This can be done by changing the ports declaration in docker-compose to:

In the end the whole docker-compose looks like:

By starting the environment with the above docker-compose we end up with:

The above is exactly as I wanted, I can use the same cluster setup external to docker with my containers.

Contribute to this site maintenance !

This is a self hosted site, on own hardware and Internet connection. The old, down to earth way πŸ™‚. If you think that you found something useful here please contribute. Choose the form below (default 1 EUR) or donate using Bitcoin (default 0.0001 BTC) using the QR code. Thank you !



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.