Search code examples
dockerdocker-swarm

Need help understanding Docker Service scale Port Binding


I understand that in docker, multiple containers cannot bind to the same port on the host machine.

If that is correct, then I would like to have an understanding of how docker service scale SERVICE=num (assuming we running this on the Manager machine) is able to create replicated containers that are all binding to the same port on host machine.

I'm confused and need help on how docker manages to make that happen.

Thanks for any support or suggested links that would help me with answers.


Solution

  • I found an answer to my question after a few research. I hope this helps someone.

    Quoted Answer from user called thaJeztha at https://github.com/moby/moby/issues/26817

    "This is expected; port publishing for services works different than for "regular" containers;

    When creating a service, ports of the containers backing the service are themselves not published directly, but go through the built-in load balancing for Swarm mode.

    Inspecting individual containers, therefore doesn't show published ports, but inspecting the service will show the ports that are published;"