nginx-proxy / docker-gen

Generate files from docker container meta-data
MIT License
4.45k stars 604 forks source link

Add ability to listen to Docker Cloud events #166

Open jasonmp85 opened 8 years ago

jasonmp85 commented 8 years ago

Description

The mapping between local Docker events and those in Docker Cloud isn't 100%, but the objects are pretty similar. Because of this, it would be great to be able to deploy docker-gen in a Docker Cloud stack and just flip a switch to have it generate templates based on Docker Cloud events rather than the local daemon ones.

Motivation

I've been working to provide Citus Docker resources, and found docker-gen incredibly easy to use with our product. In particular, I wanted to provide a docker-compose configuration that would listen to Docker events, regenerate a list of "worker nodes" (based on a label), and send a SIGHUP to a specific container. It works great.

Of course, my next thought was "hey, I can make this docker-compose.yml file work in Docker Cloud!". I hoped that there was some propagation of cloud events to the local Docker daemons, but no dice. As a short-term solution, I hacked up dockercloud-haproxy to generate my worker list file. It's not production ready yet, but it works.

However, this solution was one of convenience; if I knew Go better, I'd have added the go-dockercloud client to docker-gen, wrapped all client logic behind an interface, and added a switch to let users choose between normal Docker events or those emitted by Docker Cloud.

Proposal

Ideally, the same template language (or perhaps one resilient to missing fields) could be used whether using local events or cloud ones. The changes needed would look like:

I may have some time to look into this in the coming months (I'd have to catch up on Go), but I wanted to open the feature request in case it hadn't occurred to you how empowering this could be for instantly enabling Docker Compose stacks to run on Docker Cloud using the same templates they already use with docker-gen.

Thanks for the great project!

jwilder commented 8 years ago

Interesting idea. I'm not that familiar with docker cloud so would need to look at it more. The fields available in a template are primarily defined here: https://github.com/jwilder/docker-gen/blob/master/context.go My main concern would be if there was not a good overlap or mapping between the local docker container struct and the cloud ones.