Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 从docker运行时无法连接到服务器_Postgresql_Docker - Fatal编程技术网

Postgresql 从docker运行时无法连接到服务器

Postgresql 从docker运行时无法连接到服务器,postgresql,docker,Postgresql,Docker,我有一个连接到postgres的python代码: import psycopg2 def start_connection(host, port, name, user, pass): connect = psycopg2.connect(host=host, port=port, database=name, user=user, password=pass) return connect 当使用相同的参数从我的开发计算机运行代码时,我可以连接到postgres DB 我为我的

我有一个连接到postgres的python代码:

import psycopg2
def start_connection(host, port, name, user, pass):
   connect = psycopg2.connect(host=host, port=port, database=name, user=user, password=pass)
   return connect
当使用相同的参数从我的开发计算机运行代码时,我可以连接到postgres DB

我为我的应用程序(包含此代码)构建了一个docker

当我运行docker时(
docker运行我的\u docker:1
) 我得到一个错误:

psycopg2.operationalError could not connect to server connection timeout
Is the server running on host "184.32.99.17" and accepting TCP/IP connection on port 5432 ?
为什么我在开发计算机上运行时可以连接,而在docker上运行时不能连接? 我需要什么来修复它

注:
我检查并从docker运行的位置ping数据库

请描述postgres数据库运行的位置。我猜它可能在容器外面的远程服务器上?掌握所有信息将有助于解决问题。如果是这种情况,您可以尝试从容器中ping服务器
184.32.99.17