在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
详细信息
其他详细信息
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