docker-consul-discover is a service discovery container that leverages haproxy and consul. When running,
it sets up listeners for remote docker containers discovered via consul. It works in tandem with
How it works
When running, the container will setup ports on the host that can be accessed from other locally
running containers. For example, host port 5000 would forward requests to remote hosts running
EXPOSE port 5000. Each proxied service port is monitored with basic TCP health
checks and will be re-dispatched if backend container fails. This ensure that backend containers
can be started and stopped as needed w/ minimal client impact.
The intent is that you would run this container on any host that has containers that need to call
remote services in your infrastructure.
From within a container on a host running docker-consul-discover, they can reach remote containers by hitting
the docker bridge IP or the host IP and the corresponding
EXPOSEed port of the service.
To run it:
$ docker run -d --net host --name docker-discover -e CONSUL_HOST=18.104.22.168:8500 -p 127.0.0.1:1936:1936 -t ozzyboshi/docker-consul-discover
Then start any containers that need to access remote containers. You'll likely want to pass the host's
IP or the docker bridge IP as an env variable to make it easy for call proxied services.
You can also access the remote containers directly from the host by sending requests to the
The haproxy stats interface is exposed on port 1936. Open your browser to
http://localhost:1936 to view it.
There are a few simplifications that were made:
- TCP Proxy - By default, each listener uses haproxy's
- Round-Robin Load Balancing - Multiple containers running on different hosts are load-balanced
using a round-robin strategy. Stateful/sticky requests or master/slave type scenarios are not
- Minimal haproxy config - The haproxy template in place currently is pretty minimal and likely not ready for production use. Please feel free to submit improvements.
- Support http, udp proxying
- Support multiple ports
- Make Consul prefix configurable