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.
Together, they implement service discovery for docker containers with a similar architecture to SmartStack. docker-register is analagous to nerve in the SmartStack system.
See also Docker Service Discovery Using Etcd and Haproxy
To run it:
$ docker run -d -e HOST_IP=1.2.3.4 -e ETCD_HOST=1.2.3.4: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:
EXPOSEs
multiple ports, it won't be registered in etcd.For development, you can run the container using the following command and test your changes.
docker run -ti --rm --name docker-register -v /Users/adrianmo/.docker/machine/machines/default:/default -v $(pwd):/app -e DOCKER_TLS_VERIFY=$DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH=/default -e DOCKER_HOST=$DOCKER_HOST -e HOST_IP=127.0.0.1 adrianmo/docker-register docker-gen -interval 10 -watch -notify "echo ok" etcd.tmpl /tmp/register.py
Content type
Image
Digest
Size
176 MB
Last updated
over 10 years ago
docker pull adrianmo/docker-register