postgresql - sqlalchemy.exc.OperationalError:(psycopg2.OperationalError)无法连接到服务器:连接被拒绝
问题描述
在 docker 上启动 postgres 后,任何连接到数据库的尝试都会导致以下结果;
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
此错误的背景:http ://sqlalche.me/e/e3q8
我已经研究过类似的问题,并且我的端口是这样分配的;
ports:
- 5432:5432
细节
- 使用 venv 的烧瓶服务器
- 视窗 10
额外细节
Dockerfile(用于 postgres)
FROM postgres:9.6-alpine
COPY init-db /docker-entrypoint-initdb.d/
应用程序文件(FLASK_APP)这是破坏它的命令
@application.cli.command(with_appcontext=True)
def create_db():
db.engine.execute("CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;")
db.drop_all()
db.create_all()
容器 ID 图像命令创建的状态端口名称 f04ca2725c96 taxai_ml "gunicorn --worker-c..." 3 小时前 3 小时前 0.0.0.0:8900->5000/tcp taxai_ml_1 032fd31432af stripemock/stripe-mock "/stripe-mock -http- ...” 3 小时前 3 小时前 0.0.0.0:12111-12112->12111-12112/tcp taxai_stripe_1 795b2ff4d7d5 redis:3.2.11-alpine "docker-entrypoint.s..." 3 小时前 3 小时前 0.0.0.0:6379 ->6379/tcp taxai_redis_1
解决方案
推荐阅读
- nginx - Nginx/Lua 行为异常
- angular - Angular - 如果选中复选框,则显示组件。每个复选框都有单独的组件
- powerbi - 来自子组的总数百分比 - Power BI
- c++ - 具有“即插即用”功能的 C++ 类
- swift - 删除行后更新 indexPath 值
- dataframe - 使用 pyspark 运行时 Hive 更改表添加列问题
- r - R中的Webscraping - 获取“记录错误[[x]] ....提供的元素多于替换的元素”
- android-dialogfragment - Android DialogFragment 中的文本被截断
- python - 如何在 C 模块中包含 Python 包?
- r - left_join 嵌套列表