Using host env variable with docker remote API

687 Views Asked by At

I'm trying to use the target host's env variable to parametrize my container when launching it with the remote API, but none of these worked ...

   "Env": [
        "ENV_VAR=`$TEST`",
        "ENV_VAR2=$TEST"
   ],

Does anyone have an idea how to achieve this ?

1

There are 1 best solutions below

3
On

I'm feeding a json while POSTing to : /containers/create?name=myName -d payload.json ("Env" being in the root of the payload)

If $TEST is an environment variable from the host, the payload.json needs to include its value, not $TEST, as the POST will not change/interpret $TEST (but pass it literally).

If, instead of using a payload.json file, you used a command with the json directly in it, you could wrap the json part between double quotes: then $TEST would be interpreted by the shell.
See "How to include environment variable in bash line CURL?"