3

Does anyone have experience of running Consul Agent on AWS? I have a cluster of consul servers running, but want to use the AWS EB to deploy a docker app, and a docker consul agent (progrium/consul) to each Host instance, so that the app can use consul on the localhost, rather than all my apps talking directly back to the consul server group.

This page gives a good example of a textbook Consul network (without reference to AWS or docker etc) - https://jlordiales.me/2015/01/23/docker-consul/

Here is my Dockerrun.aws.json

{
"AWSEBDockerrunVersion": "2",
"authentication": {
    "bucket": "example-com",
    "key": "registry.example.com/example.json"
},
"containerDefinitions": [
    {
        ... php app container defined here ...
        "portMappings": [
            {
                "containerPort": 80,
                "hostPort": 80
            }
        ]
    },
    {
        "cpu": 1000,
        "entryPoint": [],
        "environment": [
            {
                "name": "CONSUL_JOIN",
                "value": "consul.example.com"
            },
            {
                "name": "CONSUL_URL",
                "value": "localhost:8500"
            }
        ],
        "essential": true,
        "image": "progrium/consul",
        "links": [],
        "memory": 900,
        "name": "consulagent",
        "portMappings": [
            {
                "containerPort": 8400,
                "hostPort": 8400
            },
            {
                "containerPort": 8500,
                "hostPort": 8500
            }
        ]
    }

]

}

Just wondering how to pass the usual arguments to my docker container to make it run as an agent and join my servers e.g. $ docker run -d -p 8400:8400 -p 8500:8500 -p 8600:53/udp \ --name node4 -h node4 progrium/consul -join $JOIN_IP

Nevyn
  • 31
  • 2
  • OK, I managed to get it working, although not quite perfect. Instead of using progrium/consul, I found gliderlabs/consulagent. This is closer to being a self-contained agent, but presumably is still expecting to be started from a `docker run ...` command with the `-join $JOIN_IP` argument, Since I had access to a private registry, I simply made a new docker container based on the one I found, but added `,"-join","$JOIN_IP"` to the RUN command. I now only need to reference a consul agent docker image in my Dockerrun.aws.json file, but its drawback is adding another bit of infra to maintain... – Nevyn Jun 06 '16 at 15:43
  • Another approach I found is to add an `.ebextensions` folder and a `*.config` file inside - see http://stackoverflow.com/a/28272729/3443312 for example. – Nevyn Jun 06 '16 at 15:46
  • Finally, I found a third option more like my original intention - adding a command to the Dockerrun.aws.json file container definition directly. (untested, as I already had a solution, but seemed worth sharing) Example from https://forums.aws.amazon.com/thread.jspa?threadID=153420&tstart=0#588601: ` { "AWSEBDockerrunVersion": 2, ... "containerDefinitions": [ { "name": "logstash", "image": "logstash:1.5", "command": [ "logstash", "-f", "/etc/logstash/conf.d/logstash.conf" ], ...` The 'command' line here seems like an undocumented feature. – Nevyn Jun 06 '16 at 15:52

0 Answers0