I've dockerize nestjs app with postgres and redis. How can I fix this issue? Postgres and redis are refusing tcp connections. This is docker-compose.yml and console result. I am using typeorm and @nestjs/bull for redis.
Hope much help. Thanks
I've dockerize nestjs app with postgres and redis. How can I fix this issue? Postgres and redis are refusing tcp connections. This is docker-compose.yml and console result. I am using typeorm and @nestjs/bull for redis.
Hope much help. Thanks
When using docker-compose, the containers do not necessarily need to specify the network they are in since they can reach each other from the container name (e.g. postgres, redis in your case) because they are in the same network. See Networking in Compose for more info.
Also, expose doesn't do any operation and it is redundant. Since you specify ports, it should be more than enough to tell Docker which ports of the container are exposed and bound to which ports of the host.
For redis-alpine, the startup command is redis-server and it is not necessary to specify it again. Also, the environment you specified is redundant in this case.
Try the following docker-compose.yaml with all of the above suggestions added:
version: "3"
services:
postgres:
image: postgres:alpine
restart: always
ports:
- 5432:5432
volumes:
- ./db_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=root
- POSTGRES_DB=lighthouse
redis:
image: redis:alpine
restart: always
ports:
- 6379:6379
Hope this helps. Cheers!