I have several containers hanging at different ports. The application used to work on the same host and, accordingly, several services exchanged data on different ports on localhost.

Is there an option to give one ip address for all containers, via Dockerfile or docker-compose?

  • Or maybe it will be easier to do so that they would not locale, but by the name of the container? then you can arbitrarily distribute - KoVadim
  • @KoVadim so far the question is “give several containers one ip address”. It may sound silly, but for now just that way =) - 1d0
  • one
    And how can the operating system scatter packets? the same ip can be given if they are on different subnets. But this is hardly what you need. - KoVadim
  • briefly: it’s possible to give something, but of course there will be no connection Specifically for multihosting, Dockers came up with swarm - aleksandr barakin

1 answer 1

Docker proposes to solve this problem with the help of the swarm mode. Make your main host a swarm manager:

docker swarm init --advertise-addr xxx.xxx.xxx.xxx:2377 

Although if you use docker-compose, you probably already have it in swarm mode.
Run to generate a second host connection command as a working

 docker swarm join-token worker 

or as a backup manager

 docker swarm join-token manager 

Copy the resulting command and run it on the second host, connecting the second host to the swam:

 docker swarm join --token <какой-то токен> xxx.xxx.xxx.xxx:2377 

Deploy your services using docker-compose on one of the managers. The docker promises that all your services via load balancer will be visible on the IP of any of the hosts, as well as deploying and administering your application can be addressed to any manager, as if all services are on the same node. enter image description here