docker-compose - how to escape environment variables
Solution 1:
Environment variables (including their name), have to be fully wrapped inside single or double quotes: ""
or ''
environment:
- 'NODE_CONFIG={"database": {"data": {"host": "mongo"}, "session": {"host": "redis" }}}'
And using double quotes:
environment:
- 'PORT=3000'
- "NODE_CONFIG={\"database\": {\"data\": {\"host\": \"mongo\"}, \"session\": {\"host\": \"redis\" }}}"
It is remarkable to note that using double quotes ""
, like bash, will allow placing variables inside the environment variable.
"MY_HOME_ENV_VARIABLE=${HOME}"