I have two docker containers running:
Postgres 9.4: 0.0.0.0:5431->5432/tcp
Postgres 11: 0.0.0.0:5432->5432/tcp
I can connect to both of them via clients on my computer, but I am unable to access one container from within another. I would like to use Postgres's dblink
feature - i.e. (in case it matters), I am running a query on one server that looks like this:
select
dp.*
from dblink(
'dbname=mydb
port=5431
host=localhost
user=postgres
password=password', 'select 1'
) as dp (i int)
This results in an error along that says:
Could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5431?
And I guess this is because localhost
is the loopback address inside the container. What is the way around this? (I'm super new to Docker by the way)