Docker Container to populate etcd server.
You can use this to create auto a auto discovery server.
- You can create a nginx running confd daemon, to read your configuration from etcd and auto create your virtual host on each docker created container .
On my POC using ECS - AWS you have to run this container on each node of your cluster, you can use user-data script to auto start this container, with auto-scale for example.
docker-register sets up a container running docker-gen. docker-gen dynamically generate a
python script when containers are started and stopped. This generated script registers the running
containers host IP and port in etcd with a TTL. It works in tandem with docker-discover which
generates haproxy routes on the host to forward requests to registered containers.
To run it:
$ docker run -d -e HOST_IP=184.108.40.206 -e ETCD_HOST=220.127.116.11:4001 -v /var/run/docker.sock:/var/run/docker.sock -t jwilder/docker-register
Then start any containers you want to be discoverable and publish their exposed port to the host.
$ docker run -d -P -t ...
If you run the container on multiple hosts, they will be grouped together automatically.
There are a few simplications that were made:
- Containers can only expose one port - This is a simplification but if the container
multiple ports, it won't be registered in etcd.
- Exposed ports must be unique to the service - Each container must expose it's service on a unique
port. For example, if you have two different backend web services and they both expose their service
over port 80, then one will need to use a port 80 and the other a different port.
- Support http, udp proxying
- Support multiple ports
- Make ETCD prefix configurable
- Support other backends (consul, zookeeper, redis, etc.)