docker-compose - how to escape environment variables : <p>With <code>docker-compose</code> v2 environment variables can be set by simply:</p>

<pre><code>enviroment:
  - MONGO_PATH=mongodb://db-mongo:27017
</code></pre>

<p>The full <code>docker-compose.yml</code> file being:</p>

<pre><code>version: '2'
services:
  web:
    build: .
    environment:
      - MONGO_PATH=mongodb://db-mongo:27017
    ports:
      - "3000:3000"
    volumes:
      - .:/app
      - /app/node_modules
    depends_on: 
      - db-mongo
      - db-redis
  db-mongo:
    image: mongo
    restart: unless-stopped
    command: --smallfiles
    ports:
      - "27017:27017"
    volumes:
      - ./data:/data/db
  [...]
</code></pre>

<p>However, how can I escape environment variables that are not a plain string?</p>

<pre><code>{"database": {"data": {"host": "mongo"}}}
</code></pre>

<p>I tried:</p>

<pre><code>NODE_CONFIG=\{"database": \{"data"\: \{"host": "mongo"\}, "session": \{"host": "redis" \}\}\}
NODE_CONFIG="\{"database": \{"data"\: \{"host": "mongo"\}, "session": \{"host": "redis" \}\}\}"
NODE_CONFIG='{"database": {"data": {"host": "mongo"}, "session": {"host": "redis" }}}'
</code></pre>

<blockquote>
  <p>ERROR: yaml.parser.ParserError: while parsing a block mapping   in
  "./docker-compose.yml", line 6, column 9 expected , but
  found '}'   in "./docker-compose.yml", line 6, column 92</p>
</blockquote>
