In docker swarm mode , i have
Worker Node 1 which has Service1 and Service2 running Worker Node 2 which has Service1 and Service2 running
Service 1 on Worker Node 1 needs to invoke API on service 2
When Service1 invokes the api, everytime its load balanced between Service2 of node1 and node2 .
How can I force docker to always reach Service 2 of node1 until it goes down ?
This is not possible.
Docker swarm does not build in any location-aware logic to its dns service discovery. The service vip for any given service will load balance round robin style across all tasks in the service regardless of where they are located.
There is an open feature request asking for this functionality: https://github.com/moby/moby/issues/32854