How can a container identify which container it is in a set of a scaled docker-compose service?

后端 未结 2 1863
萌比男神i
萌比男神i 2021-02-15 11:15

I have a docker container called node that I want to scale to n containers. A given node container needs to know which container it is in the set of n

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-15 12:14

    The latest version of docker should be able to autodiscover scaled services. For example:

    services:
      app: {}
      worker: {}
      
    

    Run scale after booting up your docker-compose:

    docker-compose scale worker=10
    

    Your app container can call the services via:

    http://worker{:port}
    

    Docker will pick a random running worker container to forward the request to.

提交回复
热议问题