title: How can one prevent variable substitution/expension in AWS Fargate container definition command
body: <p>Locally when running docker with <code>docker run</code> I pass some arguments like:</p>
  
  <pre><code>docker run -p 8080:80 -e "SERVICE_B_URL=somehost.co.uk" -d mynginx:latest /bin/sh -c "envsubst '\${SERVICE_B_URL}' &lt; /etc/nginx/conf.d/default.template &gt; /etc/nginx/conf.d/default.conf &amp;&amp; exec nginx -g 'daemon off;'"
  </code></pre>
  
  <p>This works fine. In my <code>/etc/nginx/conf.d/default.conf</code> the string <code>${SERVICE_B_URL}</code> is replaced with <code>somehost.co.uk</code>.</p>
  
  <p>When running on AWS fargate with a definition like:</p>
  
  <pre><code>"environment": [
          {
            "name": "SERVICE_B_URL",
            "value": "someotherhost.co.uk"
          }
        ],
  "command": [
          "/bin/sh",
          "-c",
          "envsubst '\\${SERVICE_B_URL}' &lt; /etc/nginx/conf.d/default.template &gt; /etc/nginx/conf.d/default.conf &amp;&amp; exec nginx -g 'daemon off;'"
        ],
  </code></pre>
  
  <p>The <code>\\</code> was to escape the <code>\</code> in the JSON file. </p>
  
  <p>When trying to run, the container exits with an error because NGINX is seeing the literal string <code>${SERVICE_B_URL}</code>. When I inspect the container and see the command AWS used to start the container it is:</p>
  
  <pre><code>Command ["/bin/sh","-c","envsubst '\\' &lt; /etc/nginx/conf.d/default.template &gt; /etc/nginx/conf.d/default.conf &amp;&amp; exec nginx -g 'daemon off;'"]
  </code></pre>
  
  <p>Notice that Fargate has attempted to expand the string <code>'\\${SERVICE_B_URL}'</code> before supplying it as a command to docker run. My intention is to specify that as a literal string.</p>
  
  <p>Is there a way to escape this/stop expansion. I've tried things like <code>'\\\\${SERVICE_B_URL}'</code> -> <code>'\\'</code>.</p>
  
  <hr>
  
  <p>Footnote, if you are wondering why I specify the <code>'\${SERVICE_B_URL}'</code> to <code>envsubst</code> instead of just using:</p>
  
  <pre><code>docker run -p 8080:80 -e "SERVICE_B_URL=somehost.co.uk" -d mynginx:latest /bin/sh -c "envsubst &lt; /etc/nginx/conf.d/default.template &gt; /etc/nginx/conf.d/default.conf &amp;&amp; exec nginx -g 'daemon off;'"
  </code></pre>
  
  <p>The reason is, that the file being substituted contains other NGINX configuration which makes use of variables with <code>$</code> syntax. So to prevent these being replaced by <code>envsubst</code> I explicitly name the variable I want to be replaced. Running locally with docker run, it works like a charm...</p>