Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marathon: How to specify environment variables in args

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.

like image 200
sliter Avatar asked Oct 29 '25 09:10

sliter


1 Answers

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"
    }
}
like image 54
Cornellius Avatar answered Oct 31 '25 09:10

Cornellius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!