{"action":"created","issue":{"url":"https://api.github.com/repos/grammarly/rocker-compose/issues/12","labels_url":"https://api.github.com/repos/grammarly/rocker-compose/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/grammarly/rocker-compose/issues/12/comments","events_url":"https://api.github.com/repos/grammarly/rocker-compose/issues/12/events","html_url":"https://github.com/grammarly/rocker-compose/issues/12","id":105073175,"number":12,"title":"link containers with ambassador pattern","user":{"login":"missedone","id":555134,"avatar_url":"https://avatars.githubusercontent.com/u/555134?v=3","gravatar_id":"","url":"https://api.github.com/users/missedone","html_url":"https://github.com/missedone","followers_url":"https://api.github.com/users/missedone/followers","following_url":"https://api.github.com/users/missedone/following{/other_user}","gists_url":"https://api.github.com/users/missedone/gists{/gist_id}","starred_url":"https://api.github.com/users/missedone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/missedone/subscriptions","organizations_url":"https://api.github.com/users/missedone/orgs","repos_url":"https://api.github.com/users/missedone/repos","events_url":"https://api.github.com/users/missedone/events{/privacy}","received_events_url":"https://api.github.com/users/missedone/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/grammarly/rocker-compose/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-06T05:45:27Z","updated_at":"2015-09-08T15:15:09Z","closed_at":null,"body":"Hi folks\r\n\r\nrocker-compose is really interesting to me, when play around with it, i'm wondering do you have plan or ever think about to support linking containers with ambassador pattern.\r\n\r\nrelate articles:\r\n* [SERVICE DISCOVERY FOR DOCKER CONTAINERS USING CONSUL AND REGISTRATOR](http://www.livewyer.com/blog/2015/02/05/service-discovery-docker-containers-using-consul-and-registrator)\r\n* [Automatic container registration with Consul and Registrator](http://jlordiales.me/2015/02/03/registrator/)\r\n\r\nin brief, i think we can extend current rocker-compose containers linking mechanism, for example, in the yaml file:\r\n```\r\nweb:\r\n    image: tomcat\r\n    net: ambassador:db\r\ndb:\r\n    image: postgres\r\n```\r\n\r\nthen, rocker-compose will start db first, and inject DB relate properties (e.g. domain, port, user, passwd, etc.) into the 'web' container as ENV variables when start it, similar as what link does.\r\n\r\nthis approach, however, will have external dependencies including a running consul container and registrator container before launch the service via `rocker-compose run`."},"comment":{"url":"https://api.github.com/repos/grammarly/rocker-compose/issues/comments/138596945","html_url":"https://github.com/grammarly/rocker-compose/issues/12#issuecomment-138596945","issue_url":"https://api.github.com/repos/grammarly/rocker-compose/issues/12","id":138596945,"user":{"login":"missedone","id":555134,"avatar_url":"https://avatars.githubusercontent.com/u/555134?v=3","gravatar_id":"","url":"https://api.github.com/users/missedone","html_url":"https://github.com/missedone","followers_url":"https://api.github.com/users/missedone/followers","following_url":"https://api.github.com/users/missedone/following{/other_user}","gists_url":"https://api.github.com/users/missedone/gists{/gist_id}","starred_url":"https://api.github.com/users/missedone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/missedone/subscriptions","organizations_url":"https://api.github.com/users/missedone/orgs","repos_url":"https://api.github.com/users/missedone/repos","events_url":"https://api.github.com/users/missedone/events{/privacy}","received_events_url":"https://api.github.com/users/missedone/received_events","type":"User","site_admin":false},"created_at":"2015-09-08T15:15:09Z","updated_at":"2015-09-08T15:15:09Z","body":"hi @ybogdanov \r\n> docker link provides a good starting point for networking construction. Communication between containers on the same host is fairly straight-forward and communication between hosts can occur over regular public networks as long as the ports are mapped correctly and the connection information is given to the other party.\r\n\r\n(quoted from [The Docker Ecosystem: Networking and Communication](https://www.digitalocean.com/community/tutorials/the-docker-ecosystem-networking-and-communication))\r\n\r\nso in case of cross multi-host networking, one approach is use ambassador pattern (aka, Service Discovery in diagram below):\r\n![Discover](https://assets.digitalocean.com/articles/docker_ecosystem/Discover-Flow.png)\r\n\r\none concrete implementation of ambassador pattern works quite great for me is use the combination of [Consul](https://www.consul.io) and [Registrator](https://github.com/gliderlabs/registrator):\r\n* Registrator listening on the docker daemon, if new container started, it registers the container info (including exposed ports, ip address, or environment variables defined in Dockerfile, etc.) into the Key-Value store Consul\r\n* Consul, beside of it's feature as a central Key-Value store, it also provide DNS service\r\n\r\nfor example, we have two container, WEB and DB, while WEB depends on DB, when DB started, it's ip, consul generated domain name, port this sort of info are registered into Consul, when WEB start, it query from Consul about the DB hostname, port etc, and update the web app's configuration file (like jdbc url, etc.)\r\n\r\nso from so good, but i think with Rocker-compose, we can abstract this service discovery process into framework level rather than inject the non-app relate logic into the container bootstrap.\r\n\r\nat Rocker-compose side, we can extend the link mechanism, when rocker-compose start the WEB container, it queries the hostname and port on-behalf of the container, and inject the properties as ENV vars to the WEB container, while the WEB container startup script only need to read the ENV var to update the configuration file, this way, we can nicely decouple the container startup with the service discovery process.\r\n\r\nregards to your concern: \r\n> in case of missing dependencies (e.g. consul-agent), you don't have a specification to run them.\r\n\r\ni think we can make rocker-compose configurable, and make the specs of Consul and Registrator as global level specs if ambassador link mode is enabled, every time before Rocker-compose run the application spec, it will run these global level specs (aka. Consul and Registrator) first to make sure the service is ready for subsequence container processing.\r\n\r\nwhat do you think?\r\nthanks"}}