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?

Tri Nguyen
  • 471
  • 1
  • 4
  • 5

4 Answers4

15

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

   environment:
     NODE_CONFIG: '{"DATABASE_URL":"http://db:5984"}'
Jumshud
  • 251
  • 2
  • 3
8

The args elements themselves need to be a string

  args:
    - 'MAVEN_USER=$MAVEN_USER'
    - 'MAVEN_PASSWORD=$MAVEN_PASSWORD'
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

TalesMGodois
  • 121
  • 3
0

You have to use = sign instead of :

example:

     - NODE_CONFIG= '{"DATABASE_URL":"http://db:5984"}'
kouhadi
  • 101
  • 1