问题似乎与Can not connect to Postgres Container from pgAdmin相同,但这些解决方案似乎都不起作用,我使用的工具略有不同...也许是不同问题?
在我的Docker桌面(运行Windows和Linux Docker)中,标准安装,我已经安装了postgres:latest镜像并从它创建了一个容器。我使用了以下设置:
容器中的日志显示成功:
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
在终端选项卡上,我可以连接到本地示例:
# 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=#
我做了一个docker inspect pgserver
,看到网络设置是这样的:
"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
}
}
}
我还安装了PGAdmin4 Docker Desktop扩展,但我无法将其配置为连接到我的postgres示例。
- 我尝试127.0.0.1在端口5432和54320上连接到www.example.com。
- 我尝试172.17.0.3在相同的端口上连接到www.example.com。
- 我尝试在相同的端口上连接到pgserver。
- 我尝试在相同的端口上连接到localhost。
- 我已确保SSL模式设置为“首选”。
根据我所使用的,我得到一个错误消息,连接被拒绝,或连接超时错误。
我做错了什么?
根据评论中的要求,docker ps
的结果如下。
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
1条答案
按热度按时间qjp7pelc1#
我有一种感觉,问题不在于docker或者端口配置,而在于postgress的配置,特别是允许定义什么连接
您可能需要将其配置为
您需要通过卷以持久的方式执行此操作