How can a container enumerate hosts available on the network?

Use case: haproxy container running with docker compose. I want to have the container discover which hosts are available in order to recreate haproxy config and reload it.

I know the there will be one or more containers named server1 and server2 available. From inside the haproxy container I can query dns for server1 and receive more than one IP address. Is that the only way to know when a new server1 cointainer becomes available or dies? I know I can use the docker api from python running inside a container that hast the docker host socket mapped to it, but I’m not sure that will work when running on swarm.

  • Jenkins: pass (environment) variable to Docker while building the image
  • AWS ECS - how to log to cloudwatch from ECS container?
  • Docker containers slow after restart in Azure VM
  • Use of container docker as a proxy for CF app to get public IP
  • Docker multi-container logging cap
  • Laradock: how to enable/install php7 ldap support extension?
  • The perfect solution would be an api or command that let’s me register an event handler that is called when a new container joins the network.

  • How can I get percentage of pull docker image?
  • Minimize docker container size built with nix
  • How to connect two HA group containers in Bluemix?
  • Nodejs private module and Docker containers
  • What if I change a Dockerfile while a build is running out of it?
  • Using Docker and Dependecy Injection Framewrok
  • One Solution collect form web for “How can a container enumerate hosts available on the network?”

    There is a solutions that you can use Registrator (https://github.com/gliderlabs/registrator), Consul and Consul Template.

    Consul is a Service Discovery
    Consul-Template watches Consul and updates HA Proxy config and reload it.
    Registrator listens Docker Engine and update Consul if there is any container is up or down.

    Please see the image:

    enter image description here

    For the full tutorial, you can refer to my blog (https://sonnguyen.ws/microservices-with-docker-swarm-and-consul/) to know how to implement it.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.