How to compose replicas to get different IPs from host network?

Hi, I am very new in docker and I’m confused about the varieties of how to set up a network.

My goal is to create multiple server containers which like to communicate on the same port. Therefore, the server containers should receive a different ip each.

I’ve tried to set up a ipvaln network but ran into two problems:

  1. I have to define IPs manually by myself
  2. There is no communication with the host network anymore.

So, how would I manage to reach my goal? Is it composable out of the box? Or are third party plugins needed? Or is a swarm needed?

Thanks alot!

Usually you use a reverse proxy to listen on a single port and then distribute requests based on domain and/or path match to internal target services.

Check nginx-proxy or see simple Traefik example, which can both automatically setup routes to the right target, based on env/labels.

Not necessarily, as docker provides ipam to assign ip addresses from the pool you specify as --ip-range when creating the ipvlan network.

Again not necessarily: the restriction is that a ipvlan (or macvlan) child interface (=what the containers use) can not communicate with its parent interface (=what the host uses). As a workaround you can assign a ipvlan child interface to the host as well. Most blog posts that discuss ipvlan/macvlan discuss this as well.

Note on Swarm: you can not assign static ip addresses for Swarm services.

Like @bluepuma77 wrote, you can use a reverse proxy if it’s for layer 7 http traffic. It works on layer 4 for https traffic leveraging SNI as well.