How `docker-compose up --scale` network work after running?

(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?

Please share your docker-compose.yml. It will help us to understand your situation.

Here is my docker-compose.yml

version: '2.1'

services:
  product:
    build: services/product
    mem_limit: 350m
    environment:
      - SPRING_PROFILES_ACTIVE=docker

  recommendation:
    build: services/recommendation
    mem_limit: 350m
    environment:
      - SPRING_PROFILES_ACTIVE=docker

  review:
    build: services/review
    mem_limit: 350m
    environment:
      - SPRING_PROFILES_ACTIVE=docker

  product-composite:
    build: services/product-composite
    mem_limit: 350m
    ports:
      - "8080:8080"
    environment:
      - SPRING_PROFILES_ACTIVE=docker

and all services Dockerfile is

FROM openjdk:12.0.2

EXPOSE 8080

ADD ./build/libs/*.jar app.jar

ENTRYPOINT ["java","-jar","/app.jar"]

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:

Imgur

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

It’s fine, I have no idea too.

There is noting about docker compose in docker website, I only found Docker Swarm detail like you said.

But thank you very much for your reply.