19

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?

  • I think the problem comes from the colon in middle, according to this comment on github issue using a dict instead of list should work (removing the leading - before NODE_CONFIG – Tensibai Jun 22 '17 at 7:47
9

The Docker Compose file reference states, that environment variables are defined as VARIABLE=value array elements. For your case, the docker-compose.yml file would need to be changed to this:

version: '3'
services:
  server:
    ports:
     - 13045:3000
    environment:
     - NODE_CONFIG='{"DATABASE_URL":"http://db:5984"}'
  • Nope. I tried that first, it doesn't work. – Tri Nguyen Jun 23 '17 at 13:18
  • @TriNguyen Strange, this works for me – Hexaholic Jun 23 '17 at 13:24
  • Well, the build would go through, but the node process doesn't pick it up. – Tri Nguyen Jun 23 '17 at 13:27
2

The args elements themselves need to be a string

  args:
    - 'MAVEN_USER=$MAVEN_USER'
    - 'MAVEN_PASSWORD=$MAVEN_PASSWORD'
  • yes, this worked for me today. – Adam Mendoza Oct 25 '18 at 3:19
2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.