1

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.

docker-compose.yml docker-compose.yml-2

result

Hope much help. Thanks

1
  • Assuming the nextjs app is running on the host machine, changing both service's network mode to "host" should work. Readup more here. Commented Mar 22, 2021 at 12:32

1 Answer 1

0

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! 🍻

Sign up to request clarification or add additional context in comments.

8 Comments

Hi, Eranga Thanks for your kind reply. I've tried following your answer but still same issue. Could you help me more? Thank you.
I believe your nest application is running in your machine locally. Not in a docker container? Also, could you check whether postgres and redis are running as containers in your machine? What is the output of docker container ls?
I added a small change to the file. I made db_data:/var/lib/postgresql/data/ --> ./db_data:/var/lib/postgresql/data/. Could you try now?
I have tried with ./db_data:/var/lib/postgresql/data/ but same.
Are you running the NestJS app in your local machine inside a docker container?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.