简体   繁体   中英

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

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 (ie scaled) containers via hostnames after docker-compose scale <component>=2 ?

根据我看到的示例,假设您的容器名称为db ,则缩放容器的名称为db_1db_2等...

When using "scale", internal docker dns service resolves only full names like projectname_db_1, projectname_db_2 and so on. Certainly, it would be better to provide in addition resolving service name + index without project name prefix.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM