0
votes

AWS opswork can deploy dockers to a cluster and so does ECS(ec2 container services). The service discovery in EC2 can be achieved using weave.net or consul etc... when we use opsworks for docker deployment, any suggestions on how to add dynamic service discovery, so inside of my docker container, I can easily get the end point of other web services deployed?

1

1 Answers

0
votes

Inside recipe you can use search that would allow you to search opsworks instances within the current stack with search(:node). This method returns array of chef nodes:

> search(:node)
=> [#<Chef::Node:0x000000070a44c8
  @attributes=
   {"aws_opsworks_instance_id"=>"----",
    "hostname"=>"--",
    "os"=>"linux",
    "platform"=>"ubuntu",
    "platform_family"=>"debian",
    "ipaddress"=>"172.31.85.144",
    "fqdn"=>"---.localdomain",
    "domain"=>"localdomain",
    "network"=>{"interfaces"=>{"aws_opsworks_virtual"=>{"addresses"=>{"172.31.85.144"=>{"family"=>"inet"}}}}},
    "kernel"=>{"machine"=>"x86_64"},
    "cloud"=>
     {"public_ips"=>["0.0.0.0"],
      "private_ips"=>["172.31.85.144"],
 ...

You can get all IP's in Opsworks stack with

> search(:node).map(&:ipaddress)
=> ["172.31.85.144", "172.31.85.31", "172.31.85.16"]

Then you can pass this list to docker resource via env variables.