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.

  • systemd, docker, or systemd-journal (on stable CoreOS) using high CPU
  • Docker container EXIT IP on system with multiple ip aliases and gateways, iptables iproute2
  • How to mount current directory as read-only but still allow changes inside the container?
  • Docker building fails randomly with Error mounting
  • How to disable linux space randomization via dockerfile?
  • Docker Deamon on Debian 7 inappropriate ioctl for device
  • 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.

  • is there a way to obtain ip of linked container using link alias?
  • How to kill process inside container? Docker top command
  • pdf2htmlEX cannot open or read file
  • Dockerfile make error code 2
  • Platform-dependent Docker images - how to?
  • How to send message by echo command to mac console? (Docker for Mac)
  • 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 (, 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 ( to know how to implement it.

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