37

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?

2

4 Answers 4

15

You need to remove dash in front of variable. Use syntax like that:

   environment:
     NODE_CONFIG: '{"DATABASE_URL":"http://db:5984"}'
8

The args elements themselves need to be a string

  args:
    - 'MAVEN_USER=$MAVEN_USER'
    - 'MAVEN_PASSWORD=$MAVEN_PASSWORD'
1
  • yes, this worked for me today. Commented Oct 25, 2018 at 3:19
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

0

You have to use = sign instead of :

example:

     - NODE_CONFIG= '{"DATABASE_URL":"http://db:5984"}'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.