Support for multiple DOCKER_HOST?
It'd be really convenient if docker-gen could support multiple (comma-separated?) values in DOCKER_HOST environment variable to be able to cleanly generate load balancer configs in a setup where backends are on different hosts.
Currently https://github.com/jwilder/docker-register & https://github.com/jwilder/docker-discover kinda do the trick but has some limitations:
- No SPDY support in HAProxy (which could be a deal breaker for many production systems).
- There is no way to access more properties of remote containers unless docker-register somehow adds these keys in etcd.
I am currently working on the following forks to overcome above limitations, but I'm already feeling dirty now:
- docker-register that registers all container ENVs with etcd
- docker-discover that replaces HAProxy with Nginx using
VIRTUAL_HOSTfrom ENVs in etcd and nginx template from https://github.com/jwilder/nginx-proxy
However, if we can add support for multiple DOCKER_HOSTs, life will be super easy; I can just use jwilder/nginx-proxy without having to do etcd+register+discover.
PS: I'd rather implement this feature then do the 2 forks described above. I'd love second opinion on the idea before I can start working.
:+1: Or even support Docker Swarm?
I'm currently on Tutum where this limitation is overcome with something like https://github.com/madwire/tutum-nginx-proxy which uses Tutum's internal discovery API. My problems with this are:
- in dev, I don't have a Tutum API
- in prod, I don't really want to rely on a proprietary API, and would prefer a "pure" Docker solution
- tutum-nginx-proxy makes for a huge image, because Ruby
UPDATE I'll do an experiment and report back here: it all depends if the API exposed by a single host is the same as Swarm's.
UPDATE 2
From https://docs.docker.com/swarm/
Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.
UPDATE 3
One of the reference docker-gen use-cases - nginx-proxy - has a related issue: jwilder/nginx-proxy/issues/97
@opyate docker-gen already supports Swarm. See here: https://github.com/jwilder/docker-gen/pull/71
Also, have a look at the blog post linked from this comment: https://github.com/jwilder/docker-gen/issues/68#issuecomment-90710788
The Docker Swarm approach is a good idea. But it doesn't fully work with docker-gen when DOCKER_HOST is set to Swarm manager, because of a bug~~(?) in swarm (https://github.com/docker/swarm/issues/1006)~~ in go's docker client library (https://github.com/samalba/dockerclient/pull/126).
Essentially docker-gen listens for container die/start/stop events. When a container is restarted, docker generates 3 die+start+restart events, first 2 of which are acted upon by docker-gen. But swarm manager generates 3 events all with status restart only, hence getting ignored by docker-gen.
Quick fix might be to include restart in the container events listener in docker-gen.
Also, it might be better to include HostIP in the Address struct to ease the lookup of Host's IP if an app does not want to use container's IP.
But swarm manager generates 3 events all with status restart only
This is now fixed by https://github.com/samalba/dockerclient/pull/126
Also, it might be better to include HostIP in the Address struct to ease the lookup of Host's IP
This also I see is already done in https://github.com/jwilder/docker-gen/pull/86
I guess docker-gen can now connect to Swarm to listen for containers on multiple docker engines/hosts.
This is now fixed by samalba/dockerclient#126
That won't help here since docker-gen uses fsouza/go-dockerclient, not samalba/dockerclient.
Oh, I see (after reading https://github.com/docker/swarm/issues/1006). Swarm itself is using samalba/dockerclient, so this will be fixed in a newer version of Swarm.
@md5 sorry, so what is the conclusion? set the DOCKER_HOST with the initial docker swarm master/manager node info, but in swarm mode, the master/manager node is always changing, right?