2

I have two public IP addresses in the same server eth0 and eth0:0.

And I have two containers that I would like them to listen on the same port but not on the same public address. My two containers are attached to the docker0

that I have :

  • eth0 =192.xx.xx.50
  • eth0:0 =192.xx.xx.51
  • container1 = 172.17.0.5 ---------> 192.xx.xx.50:443
  • container2 = 172.17.0.6 ---------> 192.xx.xx.50:9443

what I want :

  • eth0 =192.xx.xx.50
  • eth0:0 =192.xx.xx.51
  • container 1 = 172.17.0.5 ---------> 192.xx.xx.50:443
  • container 2 = 172.17.0.6 ---------> 192.xx.xx.51:443

How should I proceed to find a solution?

  1. create a new docker network? how to allocate it to the second ip address?
  2. other solutions ?

THANKS

  • Looks like what you need is a reverse proxy like nginx, ha proxy, or traefik. As no matter what you can't have two processes with one port. – Shawn C. Jan 12 '18 at 20:47

1 Answers1

2

You should be able to map the internal container port to a hostip:port combination using docker run -p ip:hostPort:containerPort ...etc...

You dont specify the internal ports in your post, but assuming the application in your container is listening on port 8080, and you want to expose this publicly as 192.168.100.1:80 then you would do:

docker run -p 192.168.100.1:80:8080 ...etc...

(see https://docs.docker.com/engine/reference/run/#expose-incoming-ports for details)

the4thamigo_uk
  • 835
  • 4
  • 8