How to reach additional containers by the hostname after docker-compose scale?

Viewed 8580

I'm using the docker-compose 1.6 with docker 1.10.1 and version 2 of docker-compose.yml.

As described in Networking in Compose, new network is created and all containers are assigned hostnames in it after docker-compose up.

How can I reach additional (i.e. scaled) containers via hostnames after docker-compose scale <component>=2?

3 Answers

I have answered that question based on python with the docker api.

You basically can use the docker api, to figure out what your project name and service name is.

Then you can filter all available containers for the same project+service to get other instances of yourself.

With the lookup of the numbers you can finally construct the hostnames.

See How to get infos about ourself in a compose cluster (backup at gist.github.com)

Related