docker-gen icon indicating copy to clipboard operation
docker-gen copied to clipboard

Support for multiple DOCKER_HOST?

Open viranch opened this issue 11 years ago • 8 comments

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:

  1. No SPDY support in HAProxy (which could be a deal breaker for many production systems).
  2. 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:

  1. docker-register that registers all container ENVs with etcd
  2. docker-discover that replaces HAProxy with Nginx using VIRTUAL_HOST from 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.

viranch avatar Jun 21 '15 18:06 viranch

:+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 avatar Jun 25 '15 09:06 opyate

@opyate docker-gen already supports Swarm. See here: https://github.com/jwilder/docker-gen/pull/71

md5 avatar Jun 25 '15 14:06 md5

Also, have a look at the blog post linked from this comment: https://github.com/jwilder/docker-gen/issues/68#issuecomment-90710788

md5 avatar Jun 25 '15 14:06 md5

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.

viranch avatar Jun 30 '15 10:06 viranch

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.

viranch avatar Jul 04 '15 14:07 viranch

This is now fixed by samalba/dockerclient#126

That won't help here since docker-gen uses fsouza/go-dockerclient, not samalba/dockerclient.

md5 avatar Jul 04 '15 15:07 md5

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 avatar Jul 04 '15 15:07 md5

@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?

ldshi avatar Nov 05 '16 10:11 ldshi