Docker Community Forums

Share and learn in the Docker community.

Why cant specify a static target port for multiple service tasks on the same host

I am pretty new to the docker swarm so I got a question when reading below in official doc:

Bypass the routing mesh

You can bypass the routing mesh, so that when you access the bound port on a given node, you are always accessing the instance of the service running on that node. This is referred to as host mode. There are a few things to keep in mind.

1.If you access a node which is not running a service task, the service does not listen on that port. It is possible that nothing is listening, or that a completely different application is listening.
2. If you expect to run multiple service tasks on each node (such as when you have 5 nodes but run 10 replicas), you cannot specify a static target port. Either allow Docker to assign a random high-numbered port (by leaving off the published), or ensure that only a single instance of the service runs on a given node, by using a global service rather than a replicated one, or by using placement constraints.

I understand the first one but not the second one.

does it mean when using host mode, a host cannot have more than one running tasks of the same service? why we cannot specify a static target port (say 80) for each task and then all bind to the same published port (say 8080) on each host?

Thanks a lot for your answer.

Let me refer you to my respond on the same topic: