【发布时间】:2019-07-05 16:45:32
【问题描述】:
我在从 Python 应用程序连接到 PostgreSQL 时遇到了一些问题。 PostgreSQL 在容器之外,因为它是一个现有的数据库。
从容器外部,数据库看起来可以访问:
$ nmap -p 5432 localhost
Starting Nmap 7.70 ( https://nmap.org ) at 2019-07-05 18:33 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00014s latency).
Other addresses for localhost (not scanned): ::1
PORT STATE SERVICE
5432/tcp open postgresql
Nmap done: 1 IP address (1 host up) scanned in 0.12 seconds
但从内部:
bash-4.4# nmap -p 5432 localhost
Starting Nmap 7.70 ( https://nmap.org ) at 2019-07-05 16:34 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000040s latency).
Other addresses for localhost (not scanned): ::1
PORT STATE SERVICE
5432/tcp closed postgresql
Nmap done: 1 IP address (1 host up) scanned in 0.41 seconds
我找不到任何类似的问题。
【问题讨论】:
-
容器的本地主机是容器本身。 Postgres 未在容器上运行,这就是您无法连接的原因。尝试使用 docker 主机的主机名或 ip 连接。 More
标签: postgresql docker networking