Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Compose throws invalid type error

I'm having an issue running docker compose. Specifically i'm getting this error:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.login-service.environment contains {"REDIS_HOST": "redis-server"}, which is an invalid type, it should be a string

And here's my yml file:

version: '3'

services:
  redis:
    image: redis
    ports:
      - 6379:6379
    networks:
      - my-network

  login-service:
    tty: true
    build: .
    volumes:
      - ./:/usr/src/app
    ports:
      - 3001:3001
    depends_on:
      - redis
    networks:
      - my-network
    environment:
      - REDIS_HOST: redis
    command: bash -c "./wait-for-it.sh redis:6379 -- npm install && npm run dev"

networks:
  my-network:

Clearly the issue is where I set my environment variable even though i've seen multiple tutorials that use the same syntax. The purpose of it is to set REDIS_HOST to whatever ip address docker assigns to Redis when building the image. Any insights what I may need to change to get this working?

like image 343
Christofer Johnson Avatar asked May 05 '18 00:05

Christofer Johnson


2 Answers

There are two different ways of implementing it. One with = sign and other with : sign. Check the following examples for more information.

Docker compose environments with = sign.

version: '3'

services:
  webserver:
    environment:
      - USER=john
      - [email protected]

Docker compose environments with : sign

version: '3'

services:
  webserver:
    environment:
      USER:john
      EMAIL:[email protected]
like image 190
Suman Kharel Avatar answered Nov 20 '22 18:11

Suman Kharel


It happens because the leading dash. You can try without it like below:

environment:
  REDIS_HOST: redis
like image 25
Jumshud Avatar answered Nov 20 '22 20:11

Jumshud