1

If I do ifconfig, docker0 ip is 172.17.0.1 and when I run my containerized app and then docker network inspect bridge myapp ip is 172.17.0.2, they are on the same network I suppose.

But inside myapp I am trying to connect to my docker host's postgresql database, I provide 172.17.0.1:5432 to my ORM but it throws an error connect ECONNREFUSED 172.17.0.1:5432.

What is the problem ?

4
  • 1
    Which OS do you use? Windows, Mac or Linux? Commented Apr 26, 2018 at 0:08
  • @KitHsu I am using Fedora 27 Commented Apr 26, 2018 at 0:23
  • I guess that the PostgreSQL is installed on the host rather than in a container. If I'm right, we should assure that PostgreSQL works well and also listens on docker0. The typical way to probe port liveness is to run nc -v 172.17.0.1 5432 on the host or netstat -np | grep 5432 to see the port state. If the port is alive, try to disable SELinux. Commented Apr 26, 2018 at 0:53
  • I have disabled SELinux and also postgresql is perfectly running fine on port 5432, i really don't see the issue. It looks like the container is blocking connection on this port. Commented Apr 26, 2018 at 1:16

2 Answers 2

2

check your pg_hba.conf file in the data directory of your postgres instance. In this file you configure which users are allowed to authenticate through which network. Make sure your postgres instance is accepting connections from the docker0 network by adding the following line:

host    all             all             172.17.0.0/24            md5

in this line you could adjust the second 'all' to specify a certain user.

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

1 Comment

Ok so I found the reason why it was not working, thanks for your answer, my postgresql installation was accepting md5 from all connections but I didn't use listen_addresses="*" in my postgresql.conf...
1

I forgot to add listen_addresses="*" in postgresql.conf ...

2 Comments

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
@DerekBrown this does provide an answer to the question. Because my question features an issue and this is how it fixes the issue I had.

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.