title: Marathon: How to specify environment variables in args
body: <p>I am trying to run a Consul container on each of my Mesos slave node.</p>
  
  <p>With Marathon I have the following JSON script:</p>
  
  <pre><code>{
      "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"]
  }
  </code></pre>
  
  <p>However, it seems that marathon treats the <code>args</code> as plain text.</p>
  
  <p>That's why I always got errors:</p>
  
  <pre><code>==&gt; Starting Consul agent...
  ==&gt; Error starting agent: Failed to start Consul client: Failed to start lan serf: Failed to create memberlist: Failed to parse advertise address!
  </code></pre>
  
  <p>So I just wonder if there are any workaround so that I can start a Consul container on each of my Mesos slave node.</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>Thanks @janisz for the link.</p>
  
  <p>After taking a look at the following discussions:</p>
  
  <ul>
  <li><p><a href="https://github.com/mesosphere/marathon/issues/3416" rel="nofollow">#3416</a>: <em>args in marathon file does not resolve env variables</em></p></li>
  <li><p><a href="https://github.com/mesosphere/marathon/issues/2679" rel="nofollow">#2679</a>: <em>Ability to specify the value of the hostname an app task is running on</em></p></li>
  <li><p><a href="https://github.com/mesosphere/marathon/issues/1328" rel="nofollow">#1328</a>: <em>Specify environment variables in the config to be used on each host through REST API</em></p></li>
  <li><p><a href="https://github.com/mesosphere/marathon/issues/1828" rel="nofollow">#1828</a>: <em>Support for more variables and variable expansion in app definition</em></p></li>
  </ul>
  
  <p>as well as the Marathon documentation on <a href="https://mesosphere.github.io/marathon/docs/task-environment-vars.html" rel="nofollow">Task Environment Variables</a>.</p>
  
  <p>My understanding is that:</p>
  
  <ul>
  <li>Currently it is not possible to pass environment variables in args</li>
  <li>Some post indicates that one could pass environment variables in <code>"cmd"</code>. But those environment variables are Task Environment Variables provided by Marathon, not the environment variables on your host machine.</li>
  </ul>
  
  <p>Please correct if I was wrong.</p>