A user, Chopper, is trying to access a PostgreSQL database from outside a Docker container on the same local server but is unable to connect, receiving a ‘Connection refused’ error despite exposing port 4002:5432 in app.yml. mpalmer suggests that the container must be rebuilt after changes and notes that the issue might be due to unmentioned customizations. mpalmer also clarifies that since the connection is local, exposing the port is unnecessary and that connecting directly to the Docker-internal IP (e.g., 172.17.0.X) on port 5432 should work.
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?
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.