4

I am trying to run a Consul container on each of my Mesos slave node.

With Marathon I have the following JSON script:

{
    "id": "consul-agent",
    "instances": 10,
    "constraints": [["hostname", "UNIQUE"]],
    "container": {
        "type": "DOCKER",
        "docker": {
            "image": "consul",
            "privileged": true,
            "network": "HOST"
        }
    },
    "args": ["agent","-bind","$MESOS_SLAVE_IP","-retry-join","$MESOS_MASTER_IP"]
}

However, it seems that marathon treats the args as plain text.

That's why I always got errors:

==> Starting Consul agent...
==> Error starting agent: Failed to start Consul client: Failed to start lan serf: Failed to create memberlist: Failed to parse advertise address!

So I just wonder if there are any workaround so that I can start a Consul container on each of my Mesos slave node.


Update:

Thanks @janisz for the link.

After taking a look at the following discussions:

  • #3416: args in marathon file does not resolve env variables

  • #2679: Ability to specify the value of the hostname an app task is running on

  • #1328: Specify environment variables in the config to be used on each host through REST API

  • #1828: Support for more variables and variable expansion in app definition

as well as the Marathon documentation on Task Environment Variables.

My understanding is that:

  • Currently it is not possible to pass environment variables in args
  • Some post indicates that one could pass environment variables in "cmd". But those environment variables are Task Environment Variables provided by Marathon, not the environment variables on your host machine.

Please correct if I was wrong.

sliter
  • 1,063
  • 1
  • 17
  • 34
  • I think this question is related to [#3416](https://github.com/mesosphere/marathon/issues/3416) – janisz Aug 19 '16 at 08:43

1 Answers1

2

You can try this.

{
    "id": "consul-agent",
    "instances": 10,
    "constraints": [["hostname", "UNIQUE"]],
    "container": {
        "type": "DOCKER",
        "docker": {
            "image": "consul",
            "privileged": true,
            "network": "HOST",
            "parameters": [
                "key": "env",
                "value": "YOUR_ENV_VAR=VALUE"
            ]
        }
    }
}

Or

{
    "id": "consul-agent",
    "instances": 10,
    "constraints": [["hostname", "UNIQUE"]],
    "container": {
        "type": "DOCKER",
        "docker": {
            "image": "consul",
            "privileged": true,
            "network": "HOST"
        }
    },
    "env": {
        "ENV_NAME" : "VALUE"
    }
}
Cornellius
  • 21
  • 2