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.

  • Docker daemon restart and reattaching to containers
  • docker - how do you disable auto-restart on a container?
  • How to properly run a Docker container as a specific host user with the same groups?
  • What is happening when docker-maven plugin tries to build image?
  • Docker container for application binaries only
  • two docker app container on one nginx
  • 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.

  • Correct way to start docker daemon listening to specific port
  • Installing Docker with sudo
  • add entry to host /etc/hosts file when a docker container is started
  • Couchbase - How to change “max_kv_size_per_doc”?
  • Duplicate mappings when building docker package using sbt-native-packager
  • Artifactory allow anonymous access for docker pull
  • 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.