我正在尝试使用我的烧瓶应用程序设置 docker,当我使用 SQLite 时,一切正常, 但是当我使用 PostgreSQL 时,该应用程序在 Pycharm IDE 中运行良好,但不会在 docker 上运行, 这是错误:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Cannot assign requested address Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
这是我对 postgres URI 的配置
app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://postgres:7421@localhost:5432/abnormal-db"
这是我为 docker 运行的代码
docker build -t rest-apis-flask-python .
docker run -dp 5000:5000 -w /app -v "/c/Users/admin/PycharmProjects/Flask-API-project:/app" rest-apis-flask-python
我也尝试查找它,我通过进入 postgres 文件并更改来解决它 pg_hba.conf 文件,我将其添加到文件末尾
host all all 0.0.0.0/0 md5
接下来我做的就是将我的 postgres URI 更改为此
"postgresql://postgres:7421@***.**.112.1:5432/abnormal-db"
我得到了“*** . **.112.1” 从在 cmd 中输入并查看 IPv4
ipconfig /all
我不确定所有这些步骤都是必要的,我也不知道为什么会出现这个问题
我花了很长时间弄清楚这个问题,我只是随机地找不到这个问题的答案
让一切正常,我尝试输入随机数但没有用,我尝试输入另一个
我的 ipconfig /all 中的 IPv4 号码在那里并且有效,localhost 和 127.0.0.1 不起作用