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?
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]
It happens because the leading dash. You can try without it like below:
environment:
REDIS_HOST: redis
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With