Accessing to the database from outside the container

How can i access to the database from ouside the container but in the same server (local)

I open the port in app.yml

expose:
  - "4002:5432" #postgres

Try to connect from outside with

psql -h 127.17.0.1 -p 4002 -d postgres -U postgres -p ''
psql: could not connect to server: Connection refused
        Is the server running on host "127.17.0.1" and accepting
        TCP/IP connections on port 5432?

What i’m missing ?

Did you rebuild the container after editing app.yml? That’s necessary to make changes effective in the running system.

2 Likes

Yep multiple time ! :weary:

I can’t reproduce the problem. If I do what you describe, it Works For Me. Presumably there’s some other sort of customisation you’ve applied, but not mentioned, that’s causing the problem.

Incidentally, since you’re running on the same machine, you don’t have to expose the port, you can just connect to the Docker-internal IP (172.17.0.<X>) on port 5432 and it should work.

3 Likes