<p>The args elements themselves need to be a string</p>

<pre><code>  args:
    - 'MAVEN_USER=$MAVEN_USER'
    - 'MAVEN_PASSWORD=$MAVEN_PASSWORD'
</code></pre>

CC BY-SA 4.0
2018-10-25T03:19:54.707Z
yes, this worked for me today.
Adam Mendoza
CC BY-SA 4.0
2018-10-15T17:30:50.243Z
2018-10-15T17:30:50.243Z
Richard Collette
<pre><code>version: '3'
services:
  server:
    ports:
     - 13045:3000
    environment:
     NODE_CONFIG: '{&quot;DATABASE_URL&quot;:&quot;http://db:5984&quot;}'
</code></pre>
<p>Just take the dash before NODE_CONFIG out. For some weird reason this dash looks to not be accepted under environment.</p>
<p>The following example is from official postgres docker hub
<a href="https://hub.docker.com/_/postgres" rel="nofollow noreferrer">https://hub.docker.com/_/postgres</a></p>
<pre><code># Use postgres/example user/password credentials
version: '3.1'

services:

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

</code></pre>
<p><strong>QQ edit:</strong></p>
<p>Basically, dashes are lists and no dashes are mappings, so that is why environment variable must not have dashes</p>
<p>References:
<a href="https://stackoverflow.com/questions/64275361/docker-compose-yml-dash-syntax-in-yaml">https://stackoverflow.com/questions/64275361/docker-compose-yml-dash-syntax-in-yaml</a>
<a href="https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html" rel="nofollow noreferrer">https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html</a></p>

CC BY-SA 4.0
2022-09-23T21:40:41.927Z
2023-08-16T19:01:18.343Z
2023-08-16T19:01:18.343Z
TalesMGodois
<p>You need to remove dash in front of variable. Use syntax like that:</p>

<pre><code>   environment:
     NODE_CONFIG: '{"DATABASE_URL":"http://db:5984"}'
</code></pre>

CC BY-SA 4.0
2019-08-17T14:46:20.723Z
2019-08-17T14:46:20.723Z
Jumshud
<p>You have to use = sign instead of :</p>
<p>example:</p>
<pre><code>     - NODE_CONFIG= '{&quot;DATABASE_URL&quot;:&quot;http://db:5984&quot;}'
</code></pre>

CC BY-SA 4.0
2024-02-22T15:17:46.157Z
2024-02-22T15:17:46.157Z
kouhadi
<p>I have the following environment variable configured in a docker-compose.yml file:</p>

<pre><code>version: '3'
services:
  server:
    ports:
     - 13045:3000
    environment:
     - NODE_CONFIG: '{"DATABASE_URL":"http://db:5984"}'
</code></pre>

<p>When trying to run <code>docker-compose up</code>, I'm getting this error:</p>

<pre><code>services.server.environment contains {"NODE_CONFIG": "{\"DATABASE_URL\":\"http://db:5984\"}"}, which is an invalid type, it should be a string
</code></pre>

<p>I need the environment variable to be set to a JSON string (see <a href="https://github.com/lorenwest/node-config/wiki/Environment-Variables#node_config" rel="noreferrer">https://github.com/lorenwest/node-config/wiki/Environment-Variables#node_config</a>)</p>

<p>Am I doing something wrong here? Can I get this to work somehow?</p>

CC BY-SA 3.0
2017-06-22T07:47:52.103Z
I think the problem comes from the colon in middle, according to [this comment on github issue](https://github.com/docker/compose/issues/2854#issuecomment-181767504) using a dict instead of list should work (removing the leading `-` before NODE_CONFIG
Tensibai
CC BY-SA 4.0
2022-04-24T20:17:31.097Z
https://stackoverflow.com/questions/50184525/docker-compose-throws-invalid-type-error
Benyamin Jafari
<docker><docker-compose>
docker-compose invalid type, it should be a string
Tri Nguyen
# docker-compose invalid type, it should be a string

(Asked by: username_0 on 2017-06-21)

I have the following environment variable configured in a docker-compose.yml file:
version: '3'
services:
  server:
    ports:
     - 13045:3000
    environment:
     - NODE_CONFIG: '{"DATABASE_URL":"http://db:5984"}'

When trying to run docker-compose up, I'm getting this error:
services.server.environment contains {"NODE_CONFIG": "{\"DATABASE_URL\":\"http://db:5984\"}"}, which is an invalid type, it should be a string

I need the environment variable to be set to a JSON string (see https://github.com/lorenwest/node-config/wiki/Environment-Variables#node_config)
Am I doing something wrong here? Can I get this to work somehow?

**Tags:** docker, docker-compose

> **Comments:**
> **username_1**: I think the problem comes from the colon in middle, according to [this comment on github issue](https://github.com/docker/compose/issues/2854#issuecomment-181767504) using a dict instead of list should work (removing the leading `-` before NODE_CONFIG  
> **username_2**: https://stackoverflow.com/questions/50184525/docker-compose-throws-invalid-type-error  

---

## 4 answers

### Answer by username_6 on 2019-08-17. Score: 15

You need to remove dash in front of variable. Use syntax like that:
   environment:
     NODE_CONFIG: '{"DATABASE_URL":"http://db:5984"}'


---

### Answer by username_3 on 2018-10-15. Score: 8

The args elements themselves need to be a string
  args:
    - 'MAVEN_USER=$MAVEN_USER'
    - 'MAVEN_PASSWORD=$MAVEN_PASSWORD'

> **Comments:**
> **username_4**: yes, this worked for me today.  

---

### Answer by username_5 on 2022-09-23. Score: 2

version: '3'
services:
  server:
    ports:
     - 13045:3000
    environment:
     NODE_CONFIG: '{"DATABASE_URL":"http://db:5984"}'

Just take the dash before NODE_CONFIG out. For some weird reason this dash looks to not be accepted under environment.
The following example is from official postgres docker hub
https://hub.docker.com/_/postgres
# Use postgres/example user/password credentials
version: '3.1'

services:

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080


QQ edit:
Basically, dashes are lists and no dashes are mappings, so that is why environment variable must not have dashes
References:
https://stackoverflow.com/questions/64275361/docker-compose-yml-dash-syntax-in-yaml
https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html


---

### Answer by username_7 on 2024-02-22. Score: 0

You have to use = sign instead of :
example:
     - NODE_CONFIG= '{"DATABASE_URL":"http://db:5984"}'


---

