(Pardon me about describe question in this post, English not my native language)
As title,
| Scenario
A service will request to B service and tell which B service response from back to A, then A response all message to user who make the request)
When I use docker-compose up --scale B=5, “B” service will build 5 containers (B_1 to B_5) and wait for “A” service request. After that, I use wrk (HTTP benchmarking tool) request “A” for 1000 times and always got response from B_1.
And next try using postman and wrk, they all got response from B_2
Network is default.
dig A will get five containers record
I found some information about DNSRR in docker docs
| Question
How docker network to decide that which “B” service container does request (Come from “A” service) go in default?
hmm, judging by your compose.yml your services have independed name and no shared hostname/network alias for the resulting containers. Even if you don’t declare a private network, the deployment will create a private network and join all services to this network.
Thus, a lookup for a servicename should respond with ip adresses for replicas of the service, but not any of the other services.
Based on this, I want to know if I use --scale product=3, it raise three product service, then DNS show me like this:
Before my test, I know each product service will serve a period time and change to another service IP, how does it work? DNS Round Robin?
Change another service like this:
Request response from 172.24.0.6
Request response from 172.24.0.6
Request response from 172.24.0.6
Request response from 172.24.0.6
Request response from 172.24.0.6
...(after mins)
Request response from 172.24.0.7
Request response from 172.24.0.7
Request response from 172.24.0.7
Request response from 172.24.0.7
Oh, I see. I completly missunderstood you. You question is regarding why DNS resolition sticks to a replica ip, before it moves to the next.
For Docker Swarm, you can set an endpoint mode for each service and define whether it should use a virtual ip (vip) that does the load balancing or returns a replica ip in dns round robin mode.
For Docker Compose, I have no idea about the implementation detail… sorry