How does service discovery work with a modern docker / docker?

I am using Docker 1.11.1 and docker-compose 1.8.0-rc2.

In the good old days (like last year), you can configure the file docker-compose.ymlas follows:

app:
  image: myapp

frontend:
  image: myfrontend
  links:
    - app

And then run the environment as follows:

docker scale app=3 frontend=1

And your interface container can check environment variables for variables with a name APP_1_PORT, APP_2_PORTetc., to find available host servers and configure accordingly.

Times have changed. Now we do it ...

version: '2'

services:
  app:
    image: myapp

  frontend:
    image: myfrontend
    links:
      - app

... and instead of environment variables we get DNS. So inside frontend, I can request app_app_1or app_app_2or app_app_3and get the corresponding IP address. I can also ask appand get an address app_app_1.

-? , getent hosts ... , :

counter=1
while :; do
  getent hosts app_$counter || break
  backends="$backends app_$counter"
  let counter++
done

.

dns, (), , () , .

?

+4

All Articles