Question seems identical to Can not connect to Postgres Container from pgAdmin but none of those solutions seem to be working, and I'm using slightly different tools... so maybe different problem?
In my Docker Desktop (running Windows with a Linux Docker), standard install, I've installed the postgres:latest image and created a container from it. I used the following settings:
The log in the container shows success:
2023-05-28 14:56:30 2023-05-28 18:56:30.313 UTC [1] LOG: starting PostgreSQL 15.3 (Debian 15.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2023-05-28 14:56:30 2023-05-28 18:56:30.313 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2023-05-28 14:56:30 2023-05-28 18:56:30.313 UTC [1] LOG: listening on IPv6 address "::", port 5432
2023-05-28 14:56:30 2023-05-28 18:56:30.319 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-05-28 14:56:30 2023-05-28 18:56:30.325 UTC [62] LOG: database system was shut down at 2023-05-28 18:56:30 UTC
2023-05-28 14:56:30 2023-05-28 18:56:30.329 UTC [1] LOG: database system is ready to accept connections
On the terminal tab, I'm able to connect to the local instance:
# psql -p 5432 -U postgres
psql (15.3 (Debian 15.3-1.pgdg110+1))
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-----------+----------+----------+------------+------------+------------+-----------------+-----------------------
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
(3 rows)
postgres=#
I did a docker inspect pgserver
and saw the network settings as such:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "7752ebc73909a6a14039b287472724b48fb8138d4466a41eb368fd91057dbcbc",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"5432/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "54320"
}
]
},
"SandboxKey": "/var/run/docker/netns/7752ebc73909",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "a00a861f13fb77a019123b42affeed42f11a8cac8ab00f609b6b2cbfc76e4ee6",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:03",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "a28aecb0b5fd55718069e079194fcf39c84a380041a82f0ec6de8f7b3565dd6a",
"EndpointID": "a00a861f13fb77a019123b42affeed42f11a8cac8ab00f609b6b2cbfc76e4ee6",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:03",
"DriverOpts": null
}
}
}
I have also installed the PGAdmin4 Docker Desktop extension, but I cannot configure it to connect to my postgres instance.
- I have tried to connect to 127.0.0.1 on ports 5432 and 54320.
- I have tried to connect to 172.17.0.3 on the same ports.
- I have tried to connect to pgserver on the same ports.
- I have tried to connect to localhost on the same ports.
- I have ensured that SSL Mode is set to "prefer".
Depending on what I use, I get an error message that the connection is refused, or a connection timeout error.
What am I doing wrong?
Per request in comments, results of docker ps
are below.
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0ed9f3f293fd postgres:latest "docker-entrypoint.s…" 20 hours ago Up 20 hours 0.0.0.0:54320->5432/tcp pgserver