使用 docker 时出现 Postgres 服务器连接错误?
I have Postgres server connection error when I use docker?
我的应用程序在我的系统上运行良好,但是当我通过 docker composer 构建 docker 图像然后 运行 应用程序时,它显示以下错误。
但是,我通过在 Flask 设置中将 IP 地址从 127.0.0.1 => 0.0.0.0 更改为如下解决了这个问题,并且 docker 图像在我的系统上工作正常。但是当我 运行 它在另一个 ubuntu 上时它给了我同样的错误并将 IP 更改为 127.0.0.1.
if __name__ == "__main__":
app.run(host='**0.0.0.0**',debug=False)
错误:
Traceback (most recent call last):
File "./main.py", line 22, in <module>
ps.create_table() # create the table if is not existed
File "/prj/Modules/postgres.py", line 49, in create_table
connection = get_connection()
File "/prj/Modules/postgres.py", line 36, in get_connection
return psycopg2.connect(f"dbname={db_name} user={user} password={password} host={host}")
File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host **"127.0.0.1"** and accepting
TCP/IP connections on port 5432?
您可以访问我的代码和我的 docker 中心:
docker 集线器:applia65/duplicatebugreportsearchengine
Github: https://github.com/ghasemieh/Duplicated-Bug-Report-Detection-System/blob/master/main.py
基本上我有 3 个容器 my-app、Postgres 和 MongoDB。
如果你能帮助我解决这个问题,我将不胜感激。
谢谢
从跟踪来看,无法访问 PostgreSql。您可以尝试更新您的 docker 撰写并添加如下公开语句:
expose:
- 5432
这将只允许访问链接服务,除非还指定了 "ports"。
我的应用程序在我的系统上运行良好,但是当我通过 docker composer 构建 docker 图像然后 运行 应用程序时,它显示以下错误。
但是,我通过在 Flask 设置中将 IP 地址从 127.0.0.1 => 0.0.0.0 更改为如下解决了这个问题,并且 docker 图像在我的系统上工作正常。但是当我 运行 它在另一个 ubuntu 上时它给了我同样的错误并将 IP 更改为 127.0.0.1.
if __name__ == "__main__":
app.run(host='**0.0.0.0**',debug=False)
错误:
Traceback (most recent call last):
File "./main.py", line 22, in <module>
ps.create_table() # create the table if is not existed
File "/prj/Modules/postgres.py", line 49, in create_table
connection = get_connection()
File "/prj/Modules/postgres.py", line 36, in get_connection
return psycopg2.connect(f"dbname={db_name} user={user} password={password} host={host}")
File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host **"127.0.0.1"** and accepting
TCP/IP connections on port 5432?
您可以访问我的代码和我的 docker 中心:
docker 集线器:applia65/duplicatebugreportsearchengine Github: https://github.com/ghasemieh/Duplicated-Bug-Report-Detection-System/blob/master/main.py
基本上我有 3 个容器 my-app、Postgres 和 MongoDB。
如果你能帮助我解决这个问题,我将不胜感激。 谢谢
从跟踪来看,无法访问 PostgreSql。您可以尝试更新您的 docker 撰写并添加如下公开语句:
expose:
- 5432
这将只允许访问链接服务,除非还指定了 "ports"。